@axiom-lattice/core 13.3.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 CHANGED
@@ -9836,7 +9836,7 @@ declare const getSandBoxManager: (key?: string) => SandboxManagerProtocol;
9836
9836
  * Every consumer that reads or writes tenant-level sandbox data (skills,
9837
9837
  * plugins, knowledge, SDK bundles, the plugin host) derives its path from
9838
9838
  * these values instead of hardcoding `/root/.agents`. New deployments default
9839
- * to the non-root runtime (`/home/appuser`, image `0.2.1`). Old root deployments
9839
+ * to the non-root runtime (`/home/appuser`, image `0.2.2`). Old root deployments
9840
9840
  * opt out with `SANDBOX_RUNTIME_PROFILE=legacy-root` (or a legacy
9841
9841
  * `SANDBOX_HOME=/root` / `0.1.0` image for backward compatibility).
9842
9842
  *
@@ -9847,7 +9847,7 @@ declare const getSandBoxManager: (key?: string) => SandboxManagerProtocol;
9847
9847
  * process user's home, not the sandbox user's home.
9848
9848
  */
9849
9849
  /** Non-root default sandbox image. */
9850
- declare const NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.1";
9850
+ declare const NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.2";
9851
9851
  /** Legacy root sandbox image. */
9852
9852
  declare const LEGACY_ROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.1.0";
9853
9853
  /** Supported sandbox runtime profiles. */
@@ -9866,7 +9866,7 @@ interface ResolvedSandboxRuntime {
9866
9866
  *
9867
9867
  * `SANDBOX_RUNTIME_PROFILE` is the single recommended switch:
9868
9868
  *
9869
- * - omitted or `nonroot`: `/home/appuser`, image `0.2.1`
9869
+ * - omitted or `nonroot`: `/home/appuser`, image `0.2.2`
9870
9870
  * - `legacy-root`: `/root`, image `0.1.0`
9871
9871
  *
9872
9872
  * For backward compatibility, an explicit `SANDBOX_HOME=/root` or pinning the
@@ -12174,6 +12174,8 @@ declare class Agent {
12174
12174
  private directInvokeAbort;
12175
12175
  private abortPromise?;
12176
12176
  private activeExecutionPromise?;
12177
+ /** Scope requested while a run is in flight; applied before the next run. */
12178
+ private pendingExecutionScope?;
12177
12179
  /**
12178
12180
  * Run signals stopped by the destructive {@link abort}.
12179
12181
  *
@@ -12240,6 +12242,19 @@ declare class Agent {
12240
12242
  workspace_id?: string | null;
12241
12243
  project_id?: string | null;
12242
12244
  }): void;
12245
+ /**
12246
+ * Re-pins scope for a dispatch without racing an in-flight run.
12247
+ *
12248
+ * Legacy entry points reuse one Agent per thread; when they carry a project
12249
+ * scope they must make it authoritative before the next sandbox is created.
12250
+ * If a run is already active, defer the update until it settles.
12251
+ */
12252
+ applyExecutionScopeIfIdle(params: {
12253
+ workspace_id?: string | null;
12254
+ project_id?: string | null;
12255
+ }): void;
12256
+ /** Applies a scope requested during the previous active execution. */
12257
+ private applyPendingExecutionScope;
12243
12258
  /**
12244
12259
  * Accepts host-authenticated queue metadata through the package-private symbol capability.
12245
12260
  *
@@ -13441,10 +13456,24 @@ declare class AgentInstanceManager {
13441
13456
  */
13442
13457
  setRunLedger(ledger: IAgentRunLedger, idFactory?: () => string): void;
13443
13458
  /**
13444
- * Get or create Agent instance for a thread
13445
- * Ensures only one instance per thread exists
13459
+ * Get or create Agent instance for a thread.
13460
+ *
13461
+ * Ensures only one instance per thread exists. Read-only callers should use
13462
+ * {@link getAgentForRead}; dispatch callers use {@link getAgentForDispatch}
13463
+ * so the run's project scope is applied before a sandbox is created.
13446
13464
  */
13447
13465
  getAgent(params: AgentThreadInterface): Agent;
13466
+ /**
13467
+ * Resolve the managed Agent for a dispatch and apply its explicit project.
13468
+ *
13469
+ * Legacy execution paths (channels, commands, cron, scheduler, Web App,
13470
+ * Open API, task comments, queue recovery) reuse the same per-thread Agent
13471
+ * instance. An explicit project must become authoritative before the next
13472
+ * sandbox is created; while a run is active it is deferred by
13473
+ * {@link Agent.applyExecutionScopeIfIdle}. Calls without a project do not
13474
+ * clear an already-established scope.
13475
+ */
13476
+ getAgentForDispatch(params: AgentThreadInterface): Agent;
13448
13477
  /**
13449
13478
  * Get the managed Agent for an exclusive execution and re-pin its scope.
13450
13479
  *
@@ -13460,14 +13489,11 @@ declare class AgentInstanceManager {
13460
13489
  /**
13461
13490
  * Get the managed Agent for a thread WITHOUT creating or registering one.
13462
13491
  *
13463
- * Read-only control-plane callers (state, memory, inbox) must not be the first
13464
- * to establish a thread's execution scope: since identity is
13465
- * `(tenant_id, assistant_id, thread_id)`, whichever caller reaches
13466
- * {@link getAgent} first fixes the instance's workspace/project for its whole
13467
- * lifetime, and a later trusted dispatch on that thread would then fail
13468
- * trusted-scope validation. This returns the existing managed instance when
13492
+ * Read-only control-plane callers (state, memory, inbox) must not mutate a
13493
+ * thread's execution scope. This returns the existing managed instance when
13469
13494
  * present, otherwise a transient unregistered Agent that is sufficient for
13470
- * state reads and disappears with the request.
13495
+ * state reads and disappears with the request. Dispatch callers use
13496
+ * {@link getAgentForDispatch}.
13471
13497
  *
13472
13498
  * @param params - Thread identity; scope is only used for the transient Agent.
13473
13499
  * @returns The managed instance if any, else an unregistered read-only Agent.
package/dist/index.d.ts CHANGED
@@ -9836,7 +9836,7 @@ declare const getSandBoxManager: (key?: string) => SandboxManagerProtocol;
9836
9836
  * Every consumer that reads or writes tenant-level sandbox data (skills,
9837
9837
  * plugins, knowledge, SDK bundles, the plugin host) derives its path from
9838
9838
  * these values instead of hardcoding `/root/.agents`. New deployments default
9839
- * to the non-root runtime (`/home/appuser`, image `0.2.1`). Old root deployments
9839
+ * to the non-root runtime (`/home/appuser`, image `0.2.2`). Old root deployments
9840
9840
  * opt out with `SANDBOX_RUNTIME_PROFILE=legacy-root` (or a legacy
9841
9841
  * `SANDBOX_HOME=/root` / `0.1.0` image for backward compatibility).
9842
9842
  *
@@ -9847,7 +9847,7 @@ declare const getSandBoxManager: (key?: string) => SandboxManagerProtocol;
9847
9847
  * process user's home, not the sandbox user's home.
9848
9848
  */
9849
9849
  /** Non-root default sandbox image. */
9850
- declare const NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.1";
9850
+ declare const NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.2";
9851
9851
  /** Legacy root sandbox image. */
9852
9852
  declare const LEGACY_ROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.1.0";
9853
9853
  /** Supported sandbox runtime profiles. */
@@ -9866,7 +9866,7 @@ interface ResolvedSandboxRuntime {
9866
9866
  *
9867
9867
  * `SANDBOX_RUNTIME_PROFILE` is the single recommended switch:
9868
9868
  *
9869
- * - omitted or `nonroot`: `/home/appuser`, image `0.2.1`
9869
+ * - omitted or `nonroot`: `/home/appuser`, image `0.2.2`
9870
9870
  * - `legacy-root`: `/root`, image `0.1.0`
9871
9871
  *
9872
9872
  * For backward compatibility, an explicit `SANDBOX_HOME=/root` or pinning the
@@ -12174,6 +12174,8 @@ declare class Agent {
12174
12174
  private directInvokeAbort;
12175
12175
  private abortPromise?;
12176
12176
  private activeExecutionPromise?;
12177
+ /** Scope requested while a run is in flight; applied before the next run. */
12178
+ private pendingExecutionScope?;
12177
12179
  /**
12178
12180
  * Run signals stopped by the destructive {@link abort}.
12179
12181
  *
@@ -12240,6 +12242,19 @@ declare class Agent {
12240
12242
  workspace_id?: string | null;
12241
12243
  project_id?: string | null;
12242
12244
  }): void;
12245
+ /**
12246
+ * Re-pins scope for a dispatch without racing an in-flight run.
12247
+ *
12248
+ * Legacy entry points reuse one Agent per thread; when they carry a project
12249
+ * scope they must make it authoritative before the next sandbox is created.
12250
+ * If a run is already active, defer the update until it settles.
12251
+ */
12252
+ applyExecutionScopeIfIdle(params: {
12253
+ workspace_id?: string | null;
12254
+ project_id?: string | null;
12255
+ }): void;
12256
+ /** Applies a scope requested during the previous active execution. */
12257
+ private applyPendingExecutionScope;
12243
12258
  /**
12244
12259
  * Accepts host-authenticated queue metadata through the package-private symbol capability.
12245
12260
  *
@@ -13441,10 +13456,24 @@ declare class AgentInstanceManager {
13441
13456
  */
13442
13457
  setRunLedger(ledger: IAgentRunLedger, idFactory?: () => string): void;
13443
13458
  /**
13444
- * Get or create Agent instance for a thread
13445
- * Ensures only one instance per thread exists
13459
+ * Get or create Agent instance for a thread.
13460
+ *
13461
+ * Ensures only one instance per thread exists. Read-only callers should use
13462
+ * {@link getAgentForRead}; dispatch callers use {@link getAgentForDispatch}
13463
+ * so the run's project scope is applied before a sandbox is created.
13446
13464
  */
13447
13465
  getAgent(params: AgentThreadInterface): Agent;
13466
+ /**
13467
+ * Resolve the managed Agent for a dispatch and apply its explicit project.
13468
+ *
13469
+ * Legacy execution paths (channels, commands, cron, scheduler, Web App,
13470
+ * Open API, task comments, queue recovery) reuse the same per-thread Agent
13471
+ * instance. An explicit project must become authoritative before the next
13472
+ * sandbox is created; while a run is active it is deferred by
13473
+ * {@link Agent.applyExecutionScopeIfIdle}. Calls without a project do not
13474
+ * clear an already-established scope.
13475
+ */
13476
+ getAgentForDispatch(params: AgentThreadInterface): Agent;
13448
13477
  /**
13449
13478
  * Get the managed Agent for an exclusive execution and re-pin its scope.
13450
13479
  *
@@ -13460,14 +13489,11 @@ declare class AgentInstanceManager {
13460
13489
  /**
13461
13490
  * Get the managed Agent for a thread WITHOUT creating or registering one.
13462
13491
  *
13463
- * Read-only control-plane callers (state, memory, inbox) must not be the first
13464
- * to establish a thread's execution scope: since identity is
13465
- * `(tenant_id, assistant_id, thread_id)`, whichever caller reaches
13466
- * {@link getAgent} first fixes the instance's workspace/project for its whole
13467
- * lifetime, and a later trusted dispatch on that thread would then fail
13468
- * trusted-scope validation. This returns the existing managed instance when
13492
+ * Read-only control-plane callers (state, memory, inbox) must not mutate a
13493
+ * thread's execution scope. This returns the existing managed instance when
13469
13494
  * present, otherwise a transient unregistered Agent that is sufficient for
13470
- * state reads and disappears with the request.
13495
+ * state reads and disappears with the request. Dispatch callers use
13496
+ * {@link getAgentForDispatch}.
13471
13497
  *
13472
13498
  * @param params - Thread identity; scope is only used for the transient Agent.
13473
13499
  * @returns The managed instance if any, else an unregistered read-only Agent.
package/dist/index.js CHANGED
@@ -9822,7 +9822,7 @@ function serializePluginMeta(plugin) {
9822
9822
  }
9823
9823
 
9824
9824
  // src/sandbox_lattice/sandboxPaths.ts
9825
- var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.1";
9825
+ var NONROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.2.2";
9826
9826
  var LEGACY_ROOT_SANDBOX_IMAGE = "kioko12520/sandbox:0.1.0";
9827
9827
  function normalizeSandboxHome(value) {
9828
9828
  const trimmed = value.trim();
@@ -31975,6 +31975,27 @@ var Agent = class {
31975
31975
  this.queue_workspace_id = params.workspace_id === null ? null : this.workspace_id;
31976
31976
  this.queue_project_id = params.project_id == null || params.project_id === "" ? null : this.project_id;
31977
31977
  }
31978
+ /**
31979
+ * Re-pins scope for a dispatch without racing an in-flight run.
31980
+ *
31981
+ * Legacy entry points reuse one Agent per thread; when they carry a project
31982
+ * scope they must make it authoritative before the next sandbox is created.
31983
+ * If a run is already active, defer the update until it settles.
31984
+ */
31985
+ applyExecutionScopeIfIdle(params) {
31986
+ if (this.activeExecutionPromise !== void 0) {
31987
+ this.pendingExecutionScope = params;
31988
+ return;
31989
+ }
31990
+ this.applyExecutionScope(params);
31991
+ }
31992
+ /** Applies a scope requested during the previous active execution. */
31993
+ applyPendingExecutionScope() {
31994
+ const pending = this.pendingExecutionScope;
31995
+ if (pending === void 0) return;
31996
+ this.pendingExecutionScope = void 0;
31997
+ this.applyExecutionScope(pending);
31998
+ }
31978
31999
  /**
31979
32000
  * Accepts host-authenticated queue metadata through the package-private symbol capability.
31980
32001
  *
@@ -33962,7 +33983,9 @@ var Agent = class {
33962
33983
  trackActiveExecution(execution) {
33963
33984
  this.activeExecutionPromise = execution;
33964
33985
  const clear = () => {
33965
- if (this.activeExecutionPromise === execution) this.activeExecutionPromise = void 0;
33986
+ if (this.activeExecutionPromise !== execution) return;
33987
+ this.activeExecutionPromise = void 0;
33988
+ this.applyPendingExecutionScope();
33966
33989
  };
33967
33990
  void execution.then(clear, clear);
33968
33991
  return execution;
@@ -34174,8 +34197,11 @@ var AgentInstanceManager = class _AgentInstanceManager {
34174
34197
  });
34175
34198
  }
34176
34199
  /**
34177
- * Get or create Agent instance for a thread
34178
- * Ensures only one instance per thread exists
34200
+ * Get or create Agent instance for a thread.
34201
+ *
34202
+ * Ensures only one instance per thread exists. Read-only callers should use
34203
+ * {@link getAgentForRead}; dispatch callers use {@link getAgentForDispatch}
34204
+ * so the run's project scope is applied before a sandbox is created.
34179
34205
  */
34180
34206
  getAgent(params) {
34181
34207
  const key6 = this.getKey(params);
@@ -34186,6 +34212,26 @@ var AgentInstanceManager = class _AgentInstanceManager {
34186
34212
  }
34187
34213
  return this.agents.get(key6);
34188
34214
  }
34215
+ /**
34216
+ * Resolve the managed Agent for a dispatch and apply its explicit project.
34217
+ *
34218
+ * Legacy execution paths (channels, commands, cron, scheduler, Web App,
34219
+ * Open API, task comments, queue recovery) reuse the same per-thread Agent
34220
+ * instance. An explicit project must become authoritative before the next
34221
+ * sandbox is created; while a run is active it is deferred by
34222
+ * {@link Agent.applyExecutionScopeIfIdle}. Calls without a project do not
34223
+ * clear an already-established scope.
34224
+ */
34225
+ getAgentForDispatch(params) {
34226
+ const agent = this.getAgent(params);
34227
+ if (typeof params.project_id === "string" && params.project_id.length > 0) {
34228
+ agent.applyExecutionScopeIfIdle({
34229
+ workspace_id: params.workspace_id,
34230
+ project_id: params.project_id
34231
+ });
34232
+ }
34233
+ return agent;
34234
+ }
34189
34235
  /**
34190
34236
  * Get the managed Agent for an exclusive execution and re-pin its scope.
34191
34237
  *
@@ -34208,14 +34254,11 @@ var AgentInstanceManager = class _AgentInstanceManager {
34208
34254
  /**
34209
34255
  * Get the managed Agent for a thread WITHOUT creating or registering one.
34210
34256
  *
34211
- * Read-only control-plane callers (state, memory, inbox) must not be the first
34212
- * to establish a thread's execution scope: since identity is
34213
- * `(tenant_id, assistant_id, thread_id)`, whichever caller reaches
34214
- * {@link getAgent} first fixes the instance's workspace/project for its whole
34215
- * lifetime, and a later trusted dispatch on that thread would then fail
34216
- * trusted-scope validation. This returns the existing managed instance when
34257
+ * Read-only control-plane callers (state, memory, inbox) must not mutate a
34258
+ * thread's execution scope. This returns the existing managed instance when
34217
34259
  * present, otherwise a transient unregistered Agent that is sufficient for
34218
- * state reads and disappears with the request.
34260
+ * state reads and disappears with the request. Dispatch callers use
34261
+ * {@link getAgentForDispatch}.
34219
34262
  *
34220
34263
  * @param params - Thread identity; scope is only used for the transient Agent.
34221
34264
  * @returns The managed instance if any, else an unregistered read-only Agent.
@@ -34328,7 +34371,7 @@ var DelegationService = class {
34328
34371
  throw new DelegatedThreadBusyError(request.thread_id);
34329
34372
  }
34330
34373
  try {
34331
- const agent = agentInstanceManager.getAgent({
34374
+ const agent = agentInstanceManager.getAgentForDispatch({
34332
34375
  assistant_id: request.assistant_id,
34333
34376
  thread_id: request.thread_id,
34334
34377
  tenant_id: request.tenantId,
@@ -35173,7 +35216,7 @@ function registerAgentAddMessageHandler() {
35173
35216
  workspace_id: runConfigFromMetadata?.workspaceId ?? "",
35174
35217
  project_id: runConfigFromMetadata?.projectId ?? ""
35175
35218
  }));
35176
- const agent = agentInstanceManager.getAgent({
35219
+ const agent = agentInstanceManager.getAgentForDispatch({
35177
35220
  tenant_id: taskInfo.tenantId,
35178
35221
  assistant_id: taskInfo.assistantId ?? "",
35179
35222
  thread_id: taskInfo.threadId ?? "",
@@ -44803,7 +44846,7 @@ var _LatticeEval = class _LatticeEval {
44803
44846
  workspace_id: this.config.workspace_id || "default",
44804
44847
  project_id: this.config.project_id || "default"
44805
44848
  };
44806
- const agent = agentInstanceManager.getAgent(agentParams);
44849
+ const agent = agentInstanceManager.getAgentForDispatch(agentParams);
44807
44850
  try {
44808
44851
  const stepInput = {
44809
44852
  message: step.override_message || inputMessage,
@@ -46790,7 +46833,7 @@ var ThreadExecutionSupervisor = class {
46790
46833
  this.probeCooldownMs = positiveOr(options.probeCooldownMs, this.cooldownMs);
46791
46834
  this.reapEveryNTicks = positiveIntegerOr(options.reapEveryNTicks, 10);
46792
46835
  this.maxInFlightAgeMs = positiveOr(options.maxInFlightAgeMs, 30 * 60 * 1e3);
46793
- this.getAgent = options.getAgent ?? ((params) => agentInstanceManager.getAgent(params));
46836
+ this.getAgent = options.getAgent ?? ((params) => agentInstanceManager.getAgentForDispatch(params));
46794
46837
  this.probeThreadRunOwner = options.probeThreadRunOwner ?? probeThreadRunOwner;
46795
46838
  this.log = options.log;
46796
46839
  }