@axiom-lattice/core 13.1.0 → 13.2.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.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +372 -191
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +227 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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()
|
|
@@ -9122,11 +9124,62 @@ var InMemoryChannelReplyJobStore = class {
|
|
|
9122
9124
|
}
|
|
9123
9125
|
};
|
|
9124
9126
|
|
|
9127
|
+
// src/store_lattice/InMemorySessionStore.ts
|
|
9128
|
+
var InMemorySessionStore = class {
|
|
9129
|
+
constructor() {
|
|
9130
|
+
this.byId = /* @__PURE__ */ new Map();
|
|
9131
|
+
this.byHash = /* @__PURE__ */ new Map();
|
|
9132
|
+
}
|
|
9133
|
+
async create(record) {
|
|
9134
|
+
this.byId.set(record.id, { ...record });
|
|
9135
|
+
this.byHash.set(record.refreshTokenHash, record.id);
|
|
9136
|
+
}
|
|
9137
|
+
async findByRefreshTokenHash(hash) {
|
|
9138
|
+
const id = this.byHash.get(hash);
|
|
9139
|
+
return id ? { ...this.byId.get(id) } : null;
|
|
9140
|
+
}
|
|
9141
|
+
async findByFamilyId(familyId) {
|
|
9142
|
+
const rows = [...this.byId.values()].filter((row) => row.familyId === familyId);
|
|
9143
|
+
const active = rows.filter((row) => !row.replacedBy && !row.revokedAt);
|
|
9144
|
+
const pool = active.length > 0 ? active : rows;
|
|
9145
|
+
pool.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
9146
|
+
return pool[0] ? { ...pool[0] } : null;
|
|
9147
|
+
}
|
|
9148
|
+
async rotate(oldId, next) {
|
|
9149
|
+
const old = this.byId.get(oldId);
|
|
9150
|
+
if (!old) return;
|
|
9151
|
+
old.replacedBy = next.id;
|
|
9152
|
+
old.lastUsedAt = next.createdAt;
|
|
9153
|
+
this.byId.set(oldId, old);
|
|
9154
|
+
await this.create(next);
|
|
9155
|
+
}
|
|
9156
|
+
async revokeFamily(familyId, _reason) {
|
|
9157
|
+
const now = /* @__PURE__ */ new Date();
|
|
9158
|
+
for (const row of this.byId.values()) {
|
|
9159
|
+
if (row.familyId === familyId && !row.revokedAt) row.revokedAt = now;
|
|
9160
|
+
}
|
|
9161
|
+
}
|
|
9162
|
+
async revokeAllForUser(userId, _reason) {
|
|
9163
|
+
const now = /* @__PURE__ */ new Date();
|
|
9164
|
+
for (const row of this.byId.values()) {
|
|
9165
|
+
if (row.userId === userId && !row.revokedAt) row.revokedAt = now;
|
|
9166
|
+
}
|
|
9167
|
+
}
|
|
9168
|
+
async touch(id, lastUsedAt) {
|
|
9169
|
+
const row = this.byId.get(id);
|
|
9170
|
+
if (row) row.lastUsedAt = lastUsedAt;
|
|
9171
|
+
}
|
|
9172
|
+
async listForUser(userId) {
|
|
9173
|
+
return [...this.byId.values()].filter((row) => row.userId === userId).map((row) => ({ ...row }));
|
|
9174
|
+
}
|
|
9175
|
+
};
|
|
9176
|
+
|
|
9125
9177
|
// src/store_lattice/configureStores.ts
|
|
9126
9178
|
var _disposables = [];
|
|
9127
9179
|
var _cleanupRegistered = false;
|
|
9128
9180
|
var _inMemoryAgentRunWarningEmitted = false;
|
|
9129
9181
|
var _inMemoryChannelReplyJobWarningEmitted = false;
|
|
9182
|
+
var _inMemorySessionWarningEmitted = false;
|
|
9130
9183
|
function registerSignalCleanup() {
|
|
9131
9184
|
if (_cleanupRegistered) return;
|
|
9132
9185
|
_cleanupRegistered = true;
|
|
@@ -9186,6 +9239,20 @@ async function configureStores(stores, options = {}) {
|
|
|
9186
9239
|
}
|
|
9187
9240
|
storeLatticeManager.registerLattice("default", "channelReplyJob", channelReplyJob);
|
|
9188
9241
|
}
|
|
9242
|
+
if (stores.session === void 0 && options.customStores?.session === void 0) {
|
|
9243
|
+
if (!_inMemorySessionWarningEmitted) {
|
|
9244
|
+
_inMemorySessionWarningEmitted = true;
|
|
9245
|
+
console.warn(
|
|
9246
|
+
"[configureStores] session is using InMemorySessionStore: sessions are non-durable and lost on restart. Configure a PostgreSQL session store for production."
|
|
9247
|
+
);
|
|
9248
|
+
}
|
|
9249
|
+
const session = new InMemorySessionStore();
|
|
9250
|
+
await initAndRegister(session, localDisposables);
|
|
9251
|
+
if (storeLatticeManager.hasLattice("default", "session")) {
|
|
9252
|
+
storeLatticeManager.removeLattice("default", "session");
|
|
9253
|
+
}
|
|
9254
|
+
storeLatticeManager.registerLattice("default", "session", session);
|
|
9255
|
+
}
|
|
9189
9256
|
if (storeLatticeManager.hasLattice("default", "connection")) {
|
|
9190
9257
|
const connectionStore = storeLatticeManager.getStoreLattice("default", "connection").store;
|
|
9191
9258
|
ConnectionRegistry.setStore(connectionStore);
|
|
@@ -14653,6 +14720,7 @@ function getBindingRegistry() {
|
|
|
14653
14720
|
}
|
|
14654
14721
|
|
|
14655
14722
|
// src/tool_lattice/manage_binding/index.ts
|
|
14723
|
+
import { maskChannelInstallationSecrets } from "@axiom-lattice/protocols";
|
|
14656
14724
|
function getInstallationStore() {
|
|
14657
14725
|
return getStoreLattice("default", "channelInstallation").store;
|
|
14658
14726
|
}
|
|
@@ -14689,6 +14757,8 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14689
14757
|
const tenantId2 = getTenantId(config);
|
|
14690
14758
|
if (!tenantId2) return failure("manage_binding requires tenant execution context");
|
|
14691
14759
|
if (input.channel === "room") return failure("Internal room bindings cannot be managed");
|
|
14760
|
+
const personalAssistantId = await resolvePersonalAssistantId(tenantId2, config);
|
|
14761
|
+
const personalInstallationIds = personalAssistantId ? await listPersonalInstallationIds(registry4, tenantId2, personalAssistantId) : null;
|
|
14692
14762
|
switch (input.action) {
|
|
14693
14763
|
case "list_installations": {
|
|
14694
14764
|
const store2 = getInstallationStore();
|
|
@@ -14696,27 +14766,42 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14696
14766
|
tenantId2,
|
|
14697
14767
|
input.channel
|
|
14698
14768
|
);
|
|
14699
|
-
return JSON.stringify({
|
|
14769
|
+
return JSON.stringify({
|
|
14770
|
+
success: true,
|
|
14771
|
+
data: installations.filter(isPublicInstallation).filter((installation) => !personalInstallationIds || personalInstallationIds.has(installation.id)).map(maskChannelInstallationSecrets)
|
|
14772
|
+
});
|
|
14700
14773
|
}
|
|
14701
14774
|
case "create": {
|
|
14702
|
-
if (!input.channel || !input.senderId
|
|
14775
|
+
if (!input.channel || !input.senderId) {
|
|
14703
14776
|
return JSON.stringify({ success: false, error: "create requires channel, senderId, and agentId" });
|
|
14704
14777
|
}
|
|
14705
|
-
|
|
14778
|
+
if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
|
|
14779
|
+
return failure("A personal assistant can only bind senders to itself");
|
|
14780
|
+
}
|
|
14781
|
+
const agentId = personalAssistantId ?? input.agentId;
|
|
14782
|
+
if (!agentId) {
|
|
14783
|
+
return JSON.stringify({ success: false, error: "create requires channel, senderId, and agentId" });
|
|
14784
|
+
}
|
|
14785
|
+
const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
|
|
14706
14786
|
if (!installId) {
|
|
14707
14787
|
return JSON.stringify({
|
|
14708
14788
|
success: false,
|
|
14709
14789
|
error: `No channelInstallationId provided and unable to auto-detect. Use action=list_installations to find available installations for channel "${input.channel}".`
|
|
14710
14790
|
});
|
|
14711
14791
|
}
|
|
14712
|
-
const validation = await validatePublicInstallation(
|
|
14792
|
+
const validation = await validatePublicInstallation(
|
|
14793
|
+
installId,
|
|
14794
|
+
tenantId2,
|
|
14795
|
+
input.channel,
|
|
14796
|
+
personalInstallationIds
|
|
14797
|
+
);
|
|
14713
14798
|
if (validation) return failure(validation);
|
|
14714
14799
|
const binding = await registry4.create({
|
|
14715
14800
|
channel: input.channel,
|
|
14716
14801
|
channelInstallationId: installId,
|
|
14717
14802
|
tenantId: tenantId2,
|
|
14718
14803
|
senderId: input.senderId,
|
|
14719
|
-
agentId
|
|
14804
|
+
agentId,
|
|
14720
14805
|
threadMode: input.threadMode,
|
|
14721
14806
|
senderDisplayName: input.senderDisplayName
|
|
14722
14807
|
});
|
|
@@ -14726,14 +14811,22 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14726
14811
|
if (!input.channel || !input.senderId) {
|
|
14727
14812
|
return JSON.stringify({ success: false, error: "update requires channel and senderId" });
|
|
14728
14813
|
}
|
|
14729
|
-
|
|
14814
|
+
if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
|
|
14815
|
+
return failure("A personal assistant can only bind senders to itself");
|
|
14816
|
+
}
|
|
14817
|
+
const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
|
|
14730
14818
|
if (!installId) {
|
|
14731
14819
|
return JSON.stringify({
|
|
14732
14820
|
success: false,
|
|
14733
14821
|
error: `No channelInstallationId provided and unable to auto-detect. Use action=list_installations first.`
|
|
14734
14822
|
});
|
|
14735
14823
|
}
|
|
14736
|
-
const validation = await validatePublicInstallation(
|
|
14824
|
+
const validation = await validatePublicInstallation(
|
|
14825
|
+
installId,
|
|
14826
|
+
tenantId2,
|
|
14827
|
+
input.channel,
|
|
14828
|
+
personalInstallationIds
|
|
14829
|
+
);
|
|
14737
14830
|
if (validation) return failure(validation);
|
|
14738
14831
|
const existing = await registry4.findBySubject({
|
|
14739
14832
|
channel: input.channel,
|
|
@@ -14747,8 +14840,11 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14747
14840
|
if (existing.channel === "room") {
|
|
14748
14841
|
return failure("Internal room bindings cannot be managed");
|
|
14749
14842
|
}
|
|
14843
|
+
if (personalAssistantId && existing.agentId !== personalAssistantId) {
|
|
14844
|
+
return JSON.stringify({ success: false, error: "Binding not found" });
|
|
14845
|
+
}
|
|
14750
14846
|
const updated = await registry4.update(tenantId2, existing.id, {
|
|
14751
|
-
agentId: input.agentId,
|
|
14847
|
+
agentId: personalAssistantId ?? input.agentId,
|
|
14752
14848
|
threadMode: input.threadMode,
|
|
14753
14849
|
senderDisplayName: input.senderDisplayName
|
|
14754
14850
|
});
|
|
@@ -14758,14 +14854,19 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14758
14854
|
if (!input.channel || !input.senderId) {
|
|
14759
14855
|
return JSON.stringify({ success: false, error: "delete requires channel and senderId" });
|
|
14760
14856
|
}
|
|
14761
|
-
const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2);
|
|
14857
|
+
const installId = input.channelInstallationId || await resolveInstallationId(input.channel, tenantId2, personalInstallationIds);
|
|
14762
14858
|
if (!installId) {
|
|
14763
14859
|
return JSON.stringify({
|
|
14764
14860
|
success: false,
|
|
14765
14861
|
error: `No channelInstallationId provided and unable to auto-detect.`
|
|
14766
14862
|
});
|
|
14767
14863
|
}
|
|
14768
|
-
const validation = await validatePublicInstallation(
|
|
14864
|
+
const validation = await validatePublicInstallation(
|
|
14865
|
+
installId,
|
|
14866
|
+
tenantId2,
|
|
14867
|
+
input.channel,
|
|
14868
|
+
personalInstallationIds
|
|
14869
|
+
);
|
|
14769
14870
|
if (validation) return failure(validation);
|
|
14770
14871
|
const existing = await registry4.findBySubject({
|
|
14771
14872
|
channel: input.channel,
|
|
@@ -14779,17 +14880,25 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14779
14880
|
if (existing.channel === "room") {
|
|
14780
14881
|
return failure("Internal room bindings cannot be managed");
|
|
14781
14882
|
}
|
|
14883
|
+
if (personalAssistantId && existing.agentId !== personalAssistantId) {
|
|
14884
|
+
return JSON.stringify({ success: false, error: "Binding not found" });
|
|
14885
|
+
}
|
|
14782
14886
|
await registry4.delete(tenantId2, existing.id);
|
|
14783
14887
|
return JSON.stringify({ success: true, message: "Binding deleted" });
|
|
14784
14888
|
}
|
|
14785
14889
|
case "list": {
|
|
14786
|
-
|
|
14890
|
+
if (personalAssistantId && input.agentId && input.agentId !== personalAssistantId) {
|
|
14891
|
+
return failure("A personal assistant can only list its own bindings");
|
|
14892
|
+
}
|
|
14893
|
+
const listed = await registry4.list({
|
|
14787
14894
|
channel: input.channel,
|
|
14788
|
-
agentId: input.agentId,
|
|
14895
|
+
agentId: personalAssistantId ?? input.agentId,
|
|
14789
14896
|
tenantId: tenantId2,
|
|
14790
14897
|
channelInstallationId: input.channelInstallationId,
|
|
14791
|
-
excludeChannels: ["room"]
|
|
14898
|
+
excludeChannels: ["room"],
|
|
14899
|
+
...personalAssistantId ? { limit: 500 } : {}
|
|
14792
14900
|
});
|
|
14901
|
+
const bindings = personalInstallationIds ? listed.filter((binding) => personalInstallationIds.has(binding.channelInstallationId)) : listed;
|
|
14793
14902
|
return JSON.stringify({ success: true, data: bindings });
|
|
14794
14903
|
}
|
|
14795
14904
|
default:
|
|
@@ -14797,33 +14906,83 @@ A sender can only be bound to ONE agent per channel+installation combination.`,
|
|
|
14797
14906
|
}
|
|
14798
14907
|
}
|
|
14799
14908
|
);
|
|
14800
|
-
async function resolveInstallationId(channel, tenantId2) {
|
|
14909
|
+
async function resolveInstallationId(channel, tenantId2, allowedIds) {
|
|
14801
14910
|
const store2 = getInstallationStore();
|
|
14802
14911
|
const installations = await store2.getInstallationsByTenant(tenantId2, channel);
|
|
14803
|
-
const publicInstallations = installations.filter(isPublicInstallation);
|
|
14912
|
+
const publicInstallations = installations.filter(isPublicInstallation).filter((installation) => !allowedIds || allowedIds.has(installation.id));
|
|
14804
14913
|
if (publicInstallations.length === 1) {
|
|
14805
14914
|
return publicInstallations[0].id;
|
|
14806
14915
|
}
|
|
14807
14916
|
return null;
|
|
14808
14917
|
}
|
|
14809
|
-
function
|
|
14918
|
+
function getRunConfig(config) {
|
|
14810
14919
|
if (typeof config !== "object" || config === null) return null;
|
|
14811
14920
|
const configurable = config.configurable;
|
|
14812
14921
|
if (typeof configurable !== "object" || configurable === null) return null;
|
|
14813
14922
|
const runConfig = configurable.runConfig;
|
|
14814
14923
|
if (typeof runConfig !== "object" || runConfig === null) return null;
|
|
14815
|
-
|
|
14816
|
-
|
|
14924
|
+
return runConfig;
|
|
14925
|
+
}
|
|
14926
|
+
function getString(record, key6) {
|
|
14927
|
+
const value = record?.[key6];
|
|
14928
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
14929
|
+
}
|
|
14930
|
+
function getTenantId(config) {
|
|
14931
|
+
return getString(getRunConfig(config), "tenantId");
|
|
14932
|
+
}
|
|
14933
|
+
async function resolvePersonalAssistantId(tenantId2, config) {
|
|
14934
|
+
const runConfig = getRunConfig(config);
|
|
14935
|
+
const assistantId = getString(runConfig, "assistant_id") ?? getString(runConfig, "assistantId");
|
|
14936
|
+
if (!assistantId) return null;
|
|
14937
|
+
try {
|
|
14938
|
+
const assistant = await getStoreLattice("default", "assistant").store.getAssistantById(tenantId2, assistantId);
|
|
14939
|
+
return assistant?.ownerUserId ? assistantId : null;
|
|
14940
|
+
} catch {
|
|
14941
|
+
return null;
|
|
14942
|
+
}
|
|
14817
14943
|
}
|
|
14818
14944
|
function isPublicInstallation(installation) {
|
|
14819
14945
|
return installation.channel !== "room";
|
|
14820
14946
|
}
|
|
14821
|
-
|
|
14947
|
+
function installationReferencesAssistant(installation, assistantId) {
|
|
14948
|
+
if (installation.fallbackAgentId === assistantId) return true;
|
|
14949
|
+
const config = installation.config;
|
|
14950
|
+
return Boolean(
|
|
14951
|
+
config && typeof config === "object" && !Array.isArray(config) && config.assistantId === assistantId
|
|
14952
|
+
);
|
|
14953
|
+
}
|
|
14954
|
+
async function listPersonalInstallationIds(registry4, tenantId2, assistantId) {
|
|
14955
|
+
const ids = /* @__PURE__ */ new Set();
|
|
14956
|
+
const installations = await getInstallationStore().getInstallationsByTenant(tenantId2);
|
|
14957
|
+
for (const installation of installations) {
|
|
14958
|
+
if (isPublicInstallation(installation) && installationReferencesAssistant(installation, assistantId)) {
|
|
14959
|
+
ids.add(installation.id);
|
|
14960
|
+
}
|
|
14961
|
+
}
|
|
14962
|
+
for (let offset = 0; ; offset += 500) {
|
|
14963
|
+
const bindings = await registry4.list({
|
|
14964
|
+
tenantId: tenantId2,
|
|
14965
|
+
agentId: assistantId,
|
|
14966
|
+
excludeChannels: ["room"],
|
|
14967
|
+
limit: 500,
|
|
14968
|
+
offset
|
|
14969
|
+
});
|
|
14970
|
+
for (const binding of bindings) {
|
|
14971
|
+
if (binding.channelInstallationId) ids.add(binding.channelInstallationId);
|
|
14972
|
+
}
|
|
14973
|
+
if (bindings.length < 500) break;
|
|
14974
|
+
}
|
|
14975
|
+
return ids;
|
|
14976
|
+
}
|
|
14977
|
+
async function validatePublicInstallation(installationId, tenantId2, channel, allowedIds) {
|
|
14822
14978
|
try {
|
|
14823
14979
|
const installation = await getInstallationStore().getInstallationById(installationId);
|
|
14824
14980
|
if (!installation || !isPublicInstallation(installation) || installation.tenantId !== tenantId2 || installation.channel !== channel) {
|
|
14825
14981
|
return "Invalid public channel installation";
|
|
14826
14982
|
}
|
|
14983
|
+
if (allowedIds && !allowedIds.has(installationId)) {
|
|
14984
|
+
return "Invalid public channel installation";
|
|
14985
|
+
}
|
|
14827
14986
|
return null;
|
|
14828
14987
|
} catch {
|
|
14829
14988
|
return "Unable to validate public channel installation";
|
|
@@ -32858,7 +33017,7 @@ import { v4 as uuidv44 } from "uuid";
|
|
|
32858
33017
|
import { ScheduledTaskStatus as ScheduledTaskStatus3, ScheduleExecutionType as ScheduleExecutionType3 } from "@axiom-lattice/protocols";
|
|
32859
33018
|
var SCHEDULE_LATTICE_KEY = "default";
|
|
32860
33019
|
var AGENT_ADD_MESSAGE_TASK_TYPE = "agent.add_message";
|
|
32861
|
-
function
|
|
33020
|
+
function getRunConfig2(config) {
|
|
32862
33021
|
const configurable = config;
|
|
32863
33022
|
return configurable?.configurable?.runConfig ?? {};
|
|
32864
33023
|
}
|
|
@@ -32939,7 +33098,7 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
32939
33098
|
tools: [
|
|
32940
33099
|
tool43(
|
|
32941
33100
|
async (input, config) => {
|
|
32942
|
-
const runConfig =
|
|
33101
|
+
const runConfig = getRunConfig2(config);
|
|
32943
33102
|
const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
|
|
32944
33103
|
const taskId = uuidv44();
|
|
32945
33104
|
const executeAt = input.executeAt;
|
|
@@ -32974,7 +33133,7 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
32974
33133
|
),
|
|
32975
33134
|
tool43(
|
|
32976
33135
|
async (input, config) => {
|
|
32977
|
-
const runConfig =
|
|
33136
|
+
const runConfig = getRunConfig2(config);
|
|
32978
33137
|
const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
|
|
32979
33138
|
const taskId = uuidv44();
|
|
32980
33139
|
const executeAt = Date.now() + input.delayMs;
|
|
@@ -33009,7 +33168,7 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
33009
33168
|
),
|
|
33010
33169
|
tool43(
|
|
33011
33170
|
async (input, config) => {
|
|
33012
|
-
const runConfig =
|
|
33171
|
+
const runConfig = getRunConfig2(config);
|
|
33013
33172
|
const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
|
|
33014
33173
|
const taskId = uuidv44();
|
|
33015
33174
|
const success = await scheduleLattice.client.scheduleCron(
|
|
@@ -33067,7 +33226,7 @@ function createSchedulerMiddleware(options = {}) {
|
|
|
33067
33226
|
),
|
|
33068
33227
|
tool43(
|
|
33069
33228
|
async (input, config) => {
|
|
33070
|
-
const runConfig =
|
|
33229
|
+
const runConfig = getRunConfig2(config);
|
|
33071
33230
|
const scheduleLattice = getScheduleLattice(SCHEDULE_LATTICE_KEY);
|
|
33072
33231
|
const storage = scheduleLattice.client.getStorage();
|
|
33073
33232
|
if (!storage) {
|
|
@@ -36345,7 +36504,9 @@ function getPersonalMcpMaxServers() {
|
|
|
36345
36504
|
return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : PERSONAL_MCP_MAX_SERVERS;
|
|
36346
36505
|
}
|
|
36347
36506
|
function getPersonalMcpSyncBudgetMs() {
|
|
36348
|
-
const
|
|
36507
|
+
const value = process.env.PERSONAL_MCP_SYNC_BUDGET_MS;
|
|
36508
|
+
if (value === void 0 || value.trim() === "") return PERSONAL_MCP_SYNC_BUDGET_MS;
|
|
36509
|
+
const raw = Number(value);
|
|
36349
36510
|
return Number.isFinite(raw) && raw >= 0 ? raw : PERSONAL_MCP_SYNC_BUDGET_MS;
|
|
36350
36511
|
}
|
|
36351
36512
|
var syncCache = /* @__PURE__ */ new Map();
|
|
@@ -36773,6 +36934,14 @@ function getTenantId2(exeConfig) {
|
|
|
36773
36934
|
const runConfig = exeConfig?.configurable?.runConfig || {};
|
|
36774
36935
|
return runConfig.tenantId || "default";
|
|
36775
36936
|
}
|
|
36937
|
+
function getRuntimeUserId(exeConfig) {
|
|
36938
|
+
const runConfig = exeConfig?.configurable?.runConfig || {};
|
|
36939
|
+
const value = runConfig.user_id ?? runConfig.userId;
|
|
36940
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
36941
|
+
}
|
|
36942
|
+
function canAccessAssistant(assistant, userId) {
|
|
36943
|
+
return !assistant.ownerUserId || userId !== null && assistant.ownerUserId === userId;
|
|
36944
|
+
}
|
|
36776
36945
|
function getAssistStore() {
|
|
36777
36946
|
return getStoreLattice("default", "assistant").store;
|
|
36778
36947
|
}
|
|
@@ -36865,17 +37034,21 @@ async function validateAgentReferences(input, tenantId2) {
|
|
|
36865
37034
|
function slugify(name) {
|
|
36866
37035
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-") || "agent";
|
|
36867
37036
|
}
|
|
37037
|
+
var MAX_AGENT_ID_ALLOCATION_ATTEMPTS = 1e3;
|
|
36868
37038
|
async function generateAgentId(tenantId2, name) {
|
|
36869
37039
|
const store2 = getAssistStore();
|
|
36870
37040
|
const base = slugify(name);
|
|
36871
37041
|
let id = base;
|
|
36872
37042
|
let counter = 2;
|
|
36873
|
-
|
|
37043
|
+
for (let attempt = 0; attempt < MAX_AGENT_ID_ALLOCATION_ATTEMPTS; attempt += 1) {
|
|
36874
37044
|
const existing = await store2.getAssistantById(tenantId2, id);
|
|
36875
37045
|
if (!existing) return id;
|
|
36876
37046
|
id = `${base}-${counter}`;
|
|
36877
|
-
counter
|
|
37047
|
+
counter += 1;
|
|
36878
37048
|
}
|
|
37049
|
+
throw new Error(
|
|
37050
|
+
`Unable to allocate a unique agent id for "${name}" after ${MAX_AGENT_ID_ALLOCATION_ATTEMPTS} attempts`
|
|
37051
|
+
);
|
|
36879
37052
|
}
|
|
36880
37053
|
registerToolLattice(
|
|
36881
37054
|
"list_agents",
|
|
@@ -36887,8 +37060,9 @@ registerToolLattice(
|
|
|
36887
37060
|
async (_input, exeConfig) => {
|
|
36888
37061
|
try {
|
|
36889
37062
|
const tenantId2 = getTenantId2(exeConfig);
|
|
37063
|
+
const userId = getRuntimeUserId(exeConfig);
|
|
36890
37064
|
const store2 = getAssistStore();
|
|
36891
|
-
const agents = await store2.getAllAssistants(tenantId2);
|
|
37065
|
+
const agents = (await store2.getAllAssistants(tenantId2)).filter((agent) => canAccessAssistant(agent, userId));
|
|
36892
37066
|
return JSON.stringify({
|
|
36893
37067
|
agents: agents.map((a) => ({
|
|
36894
37068
|
id: a.id,
|
|
@@ -36918,7 +37092,7 @@ registerToolLattice(
|
|
|
36918
37092
|
const tenantId2 = getTenantId2(exeConfig);
|
|
36919
37093
|
const store2 = getAssistStore();
|
|
36920
37094
|
const agent = await store2.getAssistantById(tenantId2, input.id);
|
|
36921
|
-
if (!agent) {
|
|
37095
|
+
if (!agent || !canAccessAssistant(agent, getRuntimeUserId(exeConfig))) {
|
|
36922
37096
|
return JSON.stringify({ error: `Agent '${input.id}' not found` });
|
|
36923
37097
|
}
|
|
36924
37098
|
return JSON.stringify(agent.graphDefinition);
|
|
@@ -37294,7 +37468,7 @@ registerToolLattice(
|
|
|
37294
37468
|
const tenantId2 = getTenantId2(exeConfig);
|
|
37295
37469
|
const store2 = getAssistStore();
|
|
37296
37470
|
const existing = await store2.getAssistantById(tenantId2, input.id);
|
|
37297
|
-
if (!existing) {
|
|
37471
|
+
if (!existing || !canAccessAssistant(existing, getRuntimeUserId(exeConfig))) {
|
|
37298
37472
|
return JSON.stringify({ error: `Agent '${input.id}' not found` });
|
|
37299
37473
|
}
|
|
37300
37474
|
const existingConfig = existing.graphDefinition || {};
|
|
@@ -37408,9 +37582,16 @@ registerToolLattice(
|
|
|
37408
37582
|
const tenantId2 = getTenantId2(exeConfig);
|
|
37409
37583
|
const store2 = getAssistStore();
|
|
37410
37584
|
const existing = await store2.getAssistantById(tenantId2, input.id);
|
|
37411
|
-
if (!existing) {
|
|
37585
|
+
if (!existing || !canAccessAssistant(existing, getRuntimeUserId(exeConfig))) {
|
|
37412
37586
|
return JSON.stringify({ error: `Agent '${input.id}' not found`, success: false });
|
|
37413
37587
|
}
|
|
37588
|
+
if (existing.ownerUserId) {
|
|
37589
|
+
return JSON.stringify({
|
|
37590
|
+
success: false,
|
|
37591
|
+
code: "PERSONAL_ASSISTANT_DELETE_UNSUPPORTED",
|
|
37592
|
+
error: "Personal assistants must be deleted from the Personal Assistant page"
|
|
37593
|
+
});
|
|
37594
|
+
}
|
|
37414
37595
|
const success = await store2.deleteAssistant(tenantId2, input.id);
|
|
37415
37596
|
if (success) {
|
|
37416
37597
|
try {
|
|
@@ -50796,7 +50977,7 @@ async function postProcessTaskMutationResponse(input) {
|
|
|
50796
50977
|
}
|
|
50797
50978
|
|
|
50798
50979
|
// src/middlewares/taskMiddleware.ts
|
|
50799
|
-
function
|
|
50980
|
+
function getRunConfig3(config) {
|
|
50800
50981
|
const c = config;
|
|
50801
50982
|
return c?.configurable?.runConfig ?? {};
|
|
50802
50983
|
}
|
|
@@ -51522,7 +51703,7 @@ function updateValuesEqual(field, requested, persisted) {
|
|
|
51522
51703
|
}
|
|
51523
51704
|
function createTaskMiddleware(options = {}) {
|
|
51524
51705
|
const handleManageTaskAction = async (input, config, validateExecutionResult, markMutation) => {
|
|
51525
|
-
const rc =
|
|
51706
|
+
const rc = getRunConfig3(config);
|
|
51526
51707
|
const authority = classifyTaskAuthority(rc);
|
|
51527
51708
|
if (authority.kind === "invalid") return trustedContextError();
|
|
51528
51709
|
const delegatedTaskId = authority.kind === "delegated" ? authority.taskId : void 0;
|
|
@@ -52650,7 +52831,7 @@ function createTaskMiddleware(options = {}) {
|
|
|
52650
52831
|
};
|
|
52651
52832
|
const reconcileExplicitExecutionResult = async (input, config, response, validationError, didMutate) => {
|
|
52652
52833
|
if (input.action !== "update" && input.action !== "set_status" && input.action !== "add_activity" || !input.id) return response;
|
|
52653
|
-
const authority = classifyTaskAuthority(
|
|
52834
|
+
const authority = classifyTaskAuthority(getRunConfig3(config));
|
|
52654
52835
|
if (authority.kind === "projectRoom" || authority.kind === "projectTask" || authority.kind === "invalid") {
|
|
52655
52836
|
return response;
|
|
52656
52837
|
}
|
|
@@ -52663,7 +52844,7 @@ function createTaskMiddleware(options = {}) {
|
|
|
52663
52844
|
mutationCommitted: didMutate,
|
|
52664
52845
|
validationError,
|
|
52665
52846
|
reconcile: async (parsed) => {
|
|
52666
|
-
const rc =
|
|
52847
|
+
const rc = getRunConfig3(config);
|
|
52667
52848
|
const tenantId2 = rc.tenantId || "default";
|
|
52668
52849
|
const workItemStore = getTaskWorkItemStore();
|
|
52669
52850
|
const task = await getTaskStore().getById(tenantId2, taskId);
|
|
@@ -52692,11 +52873,11 @@ function createTaskMiddleware(options = {}) {
|
|
|
52692
52873
|
let didMutate = false;
|
|
52693
52874
|
const validateExecutionResult = async () => {
|
|
52694
52875
|
if (!input.executionResultId || validationAttempted) return;
|
|
52695
|
-
const authority = classifyTaskAuthority(
|
|
52876
|
+
const authority = classifyTaskAuthority(getRunConfig3(config));
|
|
52696
52877
|
if (authority.kind === "projectRoom" || authority.kind === "projectTask" || authority.kind === "invalid") return;
|
|
52697
52878
|
validationAttempted = true;
|
|
52698
52879
|
try {
|
|
52699
|
-
const rc =
|
|
52880
|
+
const rc = getRunConfig3(config);
|
|
52700
52881
|
const tenantId2 = rc.tenantId || "default";
|
|
52701
52882
|
const workItemStore = getTaskWorkItemStore();
|
|
52702
52883
|
const executionResult = await workItemStore.findByEventKey(
|
|
@@ -52746,7 +52927,7 @@ function createTaskMiddleware(options = {}) {
|
|
|
52746
52927
|
);
|
|
52747
52928
|
};
|
|
52748
52929
|
const handleStartTask = async (input, config) => {
|
|
52749
|
-
const rc =
|
|
52930
|
+
const rc = getRunConfig3(config);
|
|
52750
52931
|
const authority = classifyTaskAuthority(rc);
|
|
52751
52932
|
if (authority.kind === "invalid") return trustedContextError();
|
|
52752
52933
|
if (authority.kind === "delegated") {
|
|
@@ -58557,6 +58738,9 @@ var DEFAULT_CONFIG = {
|
|
|
58557
58738
|
type: "skill",
|
|
58558
58739
|
name: "Skills",
|
|
58559
58740
|
description: "Skill system for specialized instructions and workflows",
|
|
58741
|
+
// Temporary default until skills have a per-PA resource/collection model:
|
|
58742
|
+
// keep dynamic discovery by reading all. Do NOT set `skills: []` here —
|
|
58743
|
+
// load_skills treats an explicit empty list as "no static access".
|
|
58560
58744
|
enabled: true,
|
|
58561
58745
|
config: {
|
|
58562
58746
|
readAll: true
|
|
@@ -58601,17 +58785,12 @@ var DEFAULT_CONFIG = {
|
|
|
58601
58785
|
description: "Persistent task system for human-agent coordination",
|
|
58602
58786
|
enabled: true,
|
|
58603
58787
|
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
58788
|
}
|
|
58613
58789
|
],
|
|
58614
|
-
|
|
58790
|
+
// The PA is a user-facing assistant, not a tenant agent builder. It may
|
|
58791
|
+
// discover available agents and dispatch work via `task`, but must not read,
|
|
58792
|
+
// create, or invoke agents directly.
|
|
58793
|
+
tools: ["list_agents", "manage_binding"]
|
|
58615
58794
|
};
|
|
58616
58795
|
var PersonalAssistantConfig = class {
|
|
58617
58796
|
/**
|
|
@@ -59007,6 +59186,7 @@ export {
|
|
|
59007
59186
|
InMemoryProjectRoomReadStateStore,
|
|
59008
59187
|
InMemoryProjectRoomStore,
|
|
59009
59188
|
InMemoryProjectStore,
|
|
59189
|
+
InMemorySessionStore,
|
|
59010
59190
|
InMemorySharedResourceStore,
|
|
59011
59191
|
InMemoryStore,
|
|
59012
59192
|
InMemoryTaskStore,
|