@axiom-lattice/core 13.2.0 → 13.3.1
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 +40 -12
- package/dist/index.d.ts +40 -12
- package/dist/index.js +119 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3534,6 +3534,7 @@ import { createCipheriv, createDecipheriv, randomBytes, pbkdf2Sync } from "crypt
|
|
|
3534
3534
|
var ALGORITHM = "aes-256-gcm";
|
|
3535
3535
|
var IV_LENGTH = 16;
|
|
3536
3536
|
var SALT_LENGTH = 32;
|
|
3537
|
+
var AUTH_TAG_LENGTH = 16;
|
|
3537
3538
|
var ITERATIONS = 1e5;
|
|
3538
3539
|
var DEFAULT_ENCRYPTION_KEY = "lattice-default-encryption-key-dev-only-32b!";
|
|
3539
3540
|
var cachedKey = null;
|
|
@@ -3555,7 +3556,7 @@ function encrypt(plaintext, key6) {
|
|
|
3555
3556
|
const salt = randomBytes(SALT_LENGTH);
|
|
3556
3557
|
const iv = randomBytes(IV_LENGTH);
|
|
3557
3558
|
const derivedKey = pbkdf2Sync(actualKey, salt, ITERATIONS, 32, "sha256");
|
|
3558
|
-
const cipher = createCipheriv(ALGORITHM, derivedKey, iv);
|
|
3559
|
+
const cipher = createCipheriv(ALGORITHM, derivedKey, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
3559
3560
|
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
3560
3561
|
const authTag = cipher.getAuthTag();
|
|
3561
3562
|
return Buffer.concat([salt, iv, encrypted, authTag]).toString("base64");
|
|
@@ -3565,10 +3566,10 @@ function decrypt(encrypted, key6) {
|
|
|
3565
3566
|
const data = Buffer.from(encrypted, "base64");
|
|
3566
3567
|
const salt = data.subarray(0, SALT_LENGTH);
|
|
3567
3568
|
const iv = data.subarray(SALT_LENGTH, SALT_LENGTH + IV_LENGTH);
|
|
3568
|
-
const authTag = data.subarray(-
|
|
3569
|
-
const ciphertext = data.subarray(SALT_LENGTH + IV_LENGTH, -
|
|
3569
|
+
const authTag = data.subarray(-AUTH_TAG_LENGTH);
|
|
3570
|
+
const ciphertext = data.subarray(SALT_LENGTH + IV_LENGTH, -AUTH_TAG_LENGTH);
|
|
3570
3571
|
const derivedKey = pbkdf2Sync(actualKey, salt, ITERATIONS, 32, "sha256");
|
|
3571
|
-
const decipher = createDecipheriv(ALGORITHM, derivedKey, iv);
|
|
3572
|
+
const decipher = createDecipheriv(ALGORITHM, derivedKey, iv, { authTagLength: AUTH_TAG_LENGTH });
|
|
3572
3573
|
decipher.setAuthTag(authTag);
|
|
3573
3574
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
3574
3575
|
}
|
|
@@ -7687,7 +7688,7 @@ function serializePluginMeta(plugin) {
|
|
|
7687
7688
|
}
|
|
7688
7689
|
|
|
7689
7690
|
// src/sandbox_lattice/sandboxPaths.ts
|
|
7690
|
-
var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.
|
|
7691
|
+
var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.2";
|
|
7691
7692
|
var LEGACY_ROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.1.0";
|
|
7692
7693
|
function normalizeSandboxHome(value) {
|
|
7693
7694
|
const trimmed = value.trim();
|
|
@@ -14992,6 +14993,60 @@ function failure(error) {
|
|
|
14992
14993
|
return JSON.stringify({ success: false, error });
|
|
14993
14994
|
}
|
|
14994
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
|
+
|
|
14995
15050
|
// src/tool_lattice/sql/SqlDatabaseManager.ts
|
|
14996
15051
|
function splitQualifiedTableName(qualifiedName) {
|
|
14997
15052
|
const parts = [];
|
|
@@ -15045,7 +15100,7 @@ var PostgresDatabase = class {
|
|
|
15045
15100
|
database: this.config.database,
|
|
15046
15101
|
user: this.config.user,
|
|
15047
15102
|
password: this.config.password,
|
|
15048
|
-
ssl: this.config.ssl
|
|
15103
|
+
ssl: buildSslConfig(this.config.ssl, this.config.sslRejectUnauthorized)
|
|
15049
15104
|
};
|
|
15050
15105
|
this.pool = new Pool(poolConfig);
|
|
15051
15106
|
const client = await this.pool.connect();
|
|
@@ -15205,7 +15260,7 @@ var MysqlDatabase = class {
|
|
|
15205
15260
|
database: this.config.database,
|
|
15206
15261
|
user: this.config.user,
|
|
15207
15262
|
password: this.config.password,
|
|
15208
|
-
ssl: this.config.ssl
|
|
15263
|
+
ssl: buildSslConfig(this.config.ssl, this.config.sslRejectUnauthorized)
|
|
15209
15264
|
};
|
|
15210
15265
|
this.pool = mysql.createPool({
|
|
15211
15266
|
...poolConfig,
|
|
@@ -15569,58 +15624,6 @@ var sqlDatabaseManager = SqlDatabaseManager.getInstance();
|
|
|
15569
15624
|
// src/tool_lattice/sql/list_tables_sql.ts
|
|
15570
15625
|
import z4 from "zod";
|
|
15571
15626
|
import { tool as tool2 } from "langchain";
|
|
15572
|
-
|
|
15573
|
-
// src/capability/CapabilityRuntimeAccessor.ts
|
|
15574
|
-
function getRuntimeCapabilityConfig(executionConfig, capabilityType) {
|
|
15575
|
-
return readRecordProperty(getRuntimeCapabilityPolicy(executionConfig, capabilityType), "config");
|
|
15576
|
-
}
|
|
15577
|
-
function hasRuntimeCapabilityPolicy(executionConfig, capabilityType) {
|
|
15578
|
-
return getRuntimeCapabilityPolicy(executionConfig, capabilityType) !== void 0;
|
|
15579
|
-
}
|
|
15580
|
-
function getRuntimeCapabilityPolicy(executionConfig, capabilityType) {
|
|
15581
|
-
const configurable = readRecordProperty(executionConfig, "configurable");
|
|
15582
|
-
const context = readRecordProperty(executionConfig, "context");
|
|
15583
|
-
const runConfig = readRecordProperty(configurable, "runConfig") ?? readRecordProperty(context, "runConfig");
|
|
15584
|
-
const runtime = readRecordProperty(runConfig, "capabilityRuntime");
|
|
15585
|
-
const middleware = readRecordProperty(runtime, "middleware");
|
|
15586
|
-
return readRecordProperty(middleware, capabilityType);
|
|
15587
|
-
}
|
|
15588
|
-
function getRuntimeSkillSelection(executionConfig) {
|
|
15589
|
-
const policy = getRuntimeCapabilityPolicy(executionConfig, "skill");
|
|
15590
|
-
if (!policy) return { hasPolicy: false, enabled: true, readAll: false };
|
|
15591
|
-
const config = readRecordProperty(policy, "config") ?? {};
|
|
15592
|
-
const skills = config.skills;
|
|
15593
|
-
return {
|
|
15594
|
-
hasPolicy: true,
|
|
15595
|
-
enabled: policy.enabled !== false,
|
|
15596
|
-
...Array.isArray(skills) && skills.every((skill) => typeof skill === "string") ? { skills: [...skills] } : {},
|
|
15597
|
-
readAll: config.readAll === true
|
|
15598
|
-
};
|
|
15599
|
-
}
|
|
15600
|
-
function readRecordProperty(value, property) {
|
|
15601
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
15602
|
-
const propertyValue = value[property];
|
|
15603
|
-
return typeof propertyValue === "object" && propertyValue !== null && !Array.isArray(propertyValue) ? propertyValue : void 0;
|
|
15604
|
-
}
|
|
15605
|
-
|
|
15606
|
-
// src/tool_lattice/sql/utils.ts
|
|
15607
|
-
function getEffectiveDatabaseKeys(exeConfig, staticDatabaseKeys) {
|
|
15608
|
-
const runtimeConfig = getRuntimeCapabilityConfig(exeConfig, "sql");
|
|
15609
|
-
if (runtimeConfig && Object.prototype.hasOwnProperty.call(runtimeConfig, "databaseKeys")) {
|
|
15610
|
-
const databaseKeys = runtimeConfig.databaseKeys;
|
|
15611
|
-
if (Array.isArray(databaseKeys) && databaseKeys.every((key6) => typeof key6 === "string")) {
|
|
15612
|
-
return databaseKeys;
|
|
15613
|
-
}
|
|
15614
|
-
return [];
|
|
15615
|
-
}
|
|
15616
|
-
return staticDatabaseKeys;
|
|
15617
|
-
}
|
|
15618
|
-
function getTenantIdFromConfig(exeConfig, getTenantId3) {
|
|
15619
|
-
const runConfig = exeConfig?.configurable?.runConfig || {};
|
|
15620
|
-
return runConfig.tenantId || (getTenantId3 ? getTenantId3() : "default");
|
|
15621
|
-
}
|
|
15622
|
-
|
|
15623
|
-
// src/tool_lattice/sql/list_tables_sql.ts
|
|
15624
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.`;
|
|
15625
15628
|
var SIMPLE_IDENTIFIER = /^[a-z_][a-z0-9_]*$/;
|
|
15626
15629
|
function formatIdentifier(identifier) {
|
|
@@ -29867,6 +29870,27 @@ var Agent = class {
|
|
|
29867
29870
|
this.queue_workspace_id = params.workspace_id === null ? null : this.workspace_id;
|
|
29868
29871
|
this.queue_project_id = params.project_id == null || params.project_id === "" ? null : this.project_id;
|
|
29869
29872
|
}
|
|
29873
|
+
/**
|
|
29874
|
+
* Re-pins scope for a dispatch without racing an in-flight run.
|
|
29875
|
+
*
|
|
29876
|
+
* Legacy entry points reuse one Agent per thread; when they carry a project
|
|
29877
|
+
* scope they must make it authoritative before the next sandbox is created.
|
|
29878
|
+
* If a run is already active, defer the update until it settles.
|
|
29879
|
+
*/
|
|
29880
|
+
applyExecutionScopeIfIdle(params) {
|
|
29881
|
+
if (this.activeExecutionPromise !== void 0) {
|
|
29882
|
+
this.pendingExecutionScope = params;
|
|
29883
|
+
return;
|
|
29884
|
+
}
|
|
29885
|
+
this.applyExecutionScope(params);
|
|
29886
|
+
}
|
|
29887
|
+
/** Applies a scope requested during the previous active execution. */
|
|
29888
|
+
applyPendingExecutionScope() {
|
|
29889
|
+
const pending = this.pendingExecutionScope;
|
|
29890
|
+
if (pending === void 0) return;
|
|
29891
|
+
this.pendingExecutionScope = void 0;
|
|
29892
|
+
this.applyExecutionScope(pending);
|
|
29893
|
+
}
|
|
29870
29894
|
/**
|
|
29871
29895
|
* Accepts host-authenticated queue metadata through the package-private symbol capability.
|
|
29872
29896
|
*
|
|
@@ -31854,7 +31878,9 @@ var Agent = class {
|
|
|
31854
31878
|
trackActiveExecution(execution) {
|
|
31855
31879
|
this.activeExecutionPromise = execution;
|
|
31856
31880
|
const clear = () => {
|
|
31857
|
-
if (this.activeExecutionPromise
|
|
31881
|
+
if (this.activeExecutionPromise !== execution) return;
|
|
31882
|
+
this.activeExecutionPromise = void 0;
|
|
31883
|
+
this.applyPendingExecutionScope();
|
|
31858
31884
|
};
|
|
31859
31885
|
void execution.then(clear, clear);
|
|
31860
31886
|
return execution;
|
|
@@ -32066,8 +32092,11 @@ var AgentInstanceManager = class _AgentInstanceManager {
|
|
|
32066
32092
|
});
|
|
32067
32093
|
}
|
|
32068
32094
|
/**
|
|
32069
|
-
* Get or create Agent instance for a thread
|
|
32070
|
-
*
|
|
32095
|
+
* Get or create Agent instance for a thread.
|
|
32096
|
+
*
|
|
32097
|
+
* Ensures only one instance per thread exists. Read-only callers should use
|
|
32098
|
+
* {@link getAgentForRead}; dispatch callers use {@link getAgentForDispatch}
|
|
32099
|
+
* so the run's project scope is applied before a sandbox is created.
|
|
32071
32100
|
*/
|
|
32072
32101
|
getAgent(params) {
|
|
32073
32102
|
const key6 = this.getKey(params);
|
|
@@ -32078,6 +32107,26 @@ var AgentInstanceManager = class _AgentInstanceManager {
|
|
|
32078
32107
|
}
|
|
32079
32108
|
return this.agents.get(key6);
|
|
32080
32109
|
}
|
|
32110
|
+
/**
|
|
32111
|
+
* Resolve the managed Agent for a dispatch and apply its explicit project.
|
|
32112
|
+
*
|
|
32113
|
+
* Legacy execution paths (channels, commands, cron, scheduler, Web App,
|
|
32114
|
+
* Open API, task comments, queue recovery) reuse the same per-thread Agent
|
|
32115
|
+
* instance. An explicit project must become authoritative before the next
|
|
32116
|
+
* sandbox is created; while a run is active it is deferred by
|
|
32117
|
+
* {@link Agent.applyExecutionScopeIfIdle}. Calls without a project do not
|
|
32118
|
+
* clear an already-established scope.
|
|
32119
|
+
*/
|
|
32120
|
+
getAgentForDispatch(params) {
|
|
32121
|
+
const agent = this.getAgent(params);
|
|
32122
|
+
if (typeof params.project_id === "string" && params.project_id.length > 0) {
|
|
32123
|
+
agent.applyExecutionScopeIfIdle({
|
|
32124
|
+
workspace_id: params.workspace_id,
|
|
32125
|
+
project_id: params.project_id
|
|
32126
|
+
});
|
|
32127
|
+
}
|
|
32128
|
+
return agent;
|
|
32129
|
+
}
|
|
32081
32130
|
/**
|
|
32082
32131
|
* Get the managed Agent for an exclusive execution and re-pin its scope.
|
|
32083
32132
|
*
|
|
@@ -32100,14 +32149,11 @@ var AgentInstanceManager = class _AgentInstanceManager {
|
|
|
32100
32149
|
/**
|
|
32101
32150
|
* Get the managed Agent for a thread WITHOUT creating or registering one.
|
|
32102
32151
|
*
|
|
32103
|
-
* Read-only control-plane callers (state, memory, inbox) must not
|
|
32104
|
-
*
|
|
32105
|
-
* `(tenant_id, assistant_id, thread_id)`, whichever caller reaches
|
|
32106
|
-
* {@link getAgent} first fixes the instance's workspace/project for its whole
|
|
32107
|
-
* lifetime, and a later trusted dispatch on that thread would then fail
|
|
32108
|
-
* trusted-scope validation. This returns the existing managed instance when
|
|
32152
|
+
* Read-only control-plane callers (state, memory, inbox) must not mutate a
|
|
32153
|
+
* thread's execution scope. This returns the existing managed instance when
|
|
32109
32154
|
* present, otherwise a transient unregistered Agent that is sufficient for
|
|
32110
|
-
* state reads and disappears with the request.
|
|
32155
|
+
* state reads and disappears with the request. Dispatch callers use
|
|
32156
|
+
* {@link getAgentForDispatch}.
|
|
32111
32157
|
*
|
|
32112
32158
|
* @param params - Thread identity; scope is only used for the transient Agent.
|
|
32113
32159
|
* @returns The managed instance if any, else an unregistered read-only Agent.
|
|
@@ -32220,7 +32266,7 @@ var DelegationService = class {
|
|
|
32220
32266
|
throw new DelegatedThreadBusyError(request.thread_id);
|
|
32221
32267
|
}
|
|
32222
32268
|
try {
|
|
32223
|
-
const agent = agentInstanceManager.
|
|
32269
|
+
const agent = agentInstanceManager.getAgentForDispatch({
|
|
32224
32270
|
assistant_id: request.assistant_id,
|
|
32225
32271
|
thread_id: request.thread_id,
|
|
32226
32272
|
tenant_id: request.tenantId,
|
|
@@ -33064,7 +33110,7 @@ function registerAgentAddMessageHandler() {
|
|
|
33064
33110
|
workspace_id: runConfigFromMetadata?.workspaceId ?? "",
|
|
33065
33111
|
project_id: runConfigFromMetadata?.projectId ?? ""
|
|
33066
33112
|
}));
|
|
33067
|
-
const agent = agentInstanceManager.
|
|
33113
|
+
const agent = agentInstanceManager.getAgentForDispatch({
|
|
33068
33114
|
tenant_id: taskInfo.tenantId,
|
|
33069
33115
|
assistant_id: taskInfo.assistantId ?? "",
|
|
33070
33116
|
thread_id: taskInfo.threadId ?? "",
|
|
@@ -42692,7 +42738,7 @@ var _LatticeEval = class _LatticeEval {
|
|
|
42692
42738
|
workspace_id: this.config.workspace_id || "default",
|
|
42693
42739
|
project_id: this.config.project_id || "default"
|
|
42694
42740
|
};
|
|
42695
|
-
const agent = agentInstanceManager.
|
|
42741
|
+
const agent = agentInstanceManager.getAgentForDispatch(agentParams);
|
|
42696
42742
|
try {
|
|
42697
42743
|
const stepInput = {
|
|
42698
42744
|
message: step.override_message || inputMessage,
|
|
@@ -44679,7 +44725,7 @@ var ThreadExecutionSupervisor = class {
|
|
|
44679
44725
|
this.probeCooldownMs = positiveOr(options.probeCooldownMs, this.cooldownMs);
|
|
44680
44726
|
this.reapEveryNTicks = positiveIntegerOr(options.reapEveryNTicks, 10);
|
|
44681
44727
|
this.maxInFlightAgeMs = positiveOr(options.maxInFlightAgeMs, 30 * 60 * 1e3);
|
|
44682
|
-
this.getAgent = options.getAgent ?? ((params) => agentInstanceManager.
|
|
44728
|
+
this.getAgent = options.getAgent ?? ((params) => agentInstanceManager.getAgentForDispatch(params));
|
|
44683
44729
|
this.probeThreadRunOwner = options.probeThreadRunOwner ?? probeThreadRunOwner;
|
|
44684
44730
|
this.log = options.log;
|
|
44685
44731
|
}
|