@tangle-network/agent-app 0.44.30 → 0.44.32

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.
@@ -727,6 +727,87 @@ interface SandboxPrewarmer {
727
727
  }
728
728
  declare function createSandboxPrewarmer(shell: SandboxRuntimeConfig, options: SandboxPrewarmerOptions): SandboxPrewarmer;
729
729
 
730
+ /**
731
+ * `createD1PrewarmClaimStore` — the cross-isolate half of
732
+ * `createSandboxPrewarmer`'s single-flight, implemented once.
733
+ *
734
+ * WHY THIS SHIPS HERE. `SandboxPrewarmerOptions.claim` is REQUIRED and has no
735
+ * default, which is correct — the unsafe behaviour must be said out loud. But
736
+ * "required with no implementation" is how five products end up hand-rolling
737
+ * five subtly different atomic leases, and a lease that is subtly wrong is
738
+ * indistinguishable from one that works until two tabs leak a box. Every
739
+ * agent-app product deploys to Cloudflare Workers with a D1 binding, so the
740
+ * store is the same code in all of them: it is mechanism, not domain, and it
741
+ * belongs beside the prewarmer.
742
+ *
743
+ * The measured stake (staging-sandbox, 2026-07-28): two concurrent
744
+ * `POST /v1/sandboxes` with an identical name BOTH returned HTTP 201 and left
745
+ * two running boxes. The platform does not dedupe by name, so nothing below
746
+ * this line is defensive programming — an unclaimed race genuinely doubles
747
+ * spend.
748
+ *
749
+ * ── ATOMICITY IS THE WHOLE POINT ───────────────────────────────────────────
750
+ * `acquire` is ONE statement. A `SELECT` followed by an `INSERT` is exactly the
751
+ * race this exists to close: both isolates read "free", both write, both warm.
752
+ * The upsert's `DO UPDATE ... WHERE expires_at <= now` means an unexpired claim
753
+ * makes the conflict path a no-op, and `RETURNING` then yields no row — so the
754
+ * loser learns it lost from the same statement that would have made it the
755
+ * winner. `RETURNING` is used rather than `meta.changes` because a no-op upsert
756
+ * reporting `changes: 0` is a SQLite detail, whereas "no row came back" is the
757
+ * statement telling you directly.
758
+ *
759
+ * ── STRUCTURAL, NOT A DEPENDENCY ───────────────────────────────────────────
760
+ * The binding is taken as the narrow shape actually used (`prepare().bind()`,
761
+ * `.first()`, `.run()`), per the package's structural-over-hard-dep rule. No
762
+ * `@cloudflare/workers-types` import, so `/sandbox` stays importable in a plain
763
+ * node test. A real `D1Database` satisfies it.
764
+ *
765
+ * ── THE TABLE IS THE PRODUCT'S MIGRATION, NOT A LAZY CREATE ────────────────
766
+ * The store never runs DDL. A `CREATE TABLE IF NOT EXISTS` on every project
767
+ * open costs a round trip on the exact path this feature exists to keep fast,
768
+ * and it hides schema drift instead of failing on it. `PREWARM_CLAIM_TABLE_DDL`
769
+ * is exported so a product pastes it into a real migration. If the table is
770
+ * missing, `acquire` throws — and the prewarmer treats a throwing claim as a
771
+ * failed warm: it records the failure, emits `onEvent({type:'failed'})`, and
772
+ * degrades to the lazy path. Fail-closed and loud, never a silent double-warm.
773
+ */
774
+ /** The columns and statements this store uses, and nothing else. A real
775
+ * `D1Database` structurally satisfies it. */
776
+ interface PrewarmClaimD1Like {
777
+ prepare(query: string): {
778
+ bind(...values: unknown[]): {
779
+ first<T = Record<string, unknown>>(): Promise<T | null>;
780
+ run(): Promise<unknown>;
781
+ };
782
+ };
783
+ }
784
+ interface D1PrewarmClaimStoreOptions {
785
+ /** Defaults to `sandbox_prewarm_claims`. Must be a bare SQL identifier — it
786
+ * is interpolated, because a table name cannot be a bound parameter. */
787
+ table?: string;
788
+ /** Clock seam for tests. */
789
+ now?(): number;
790
+ }
791
+ declare const DEFAULT_PREWARM_CLAIM_TABLE = "sandbox_prewarm_claims";
792
+ /** Paste into a migration. `expires_at` is epoch MILLISECONDS, matching
793
+ * `Date.now()`, so no unit conversion sits between the lease and its clock. */
794
+ declare const PREWARM_CLAIM_TABLE_DDL = "CREATE TABLE IF NOT EXISTS sandbox_prewarm_claims (\n key TEXT PRIMARY KEY,\n expires_at INTEGER NOT NULL\n)";
795
+ /**
796
+ * A `PrewarmClaimStore` backed by one D1 table.
797
+ *
798
+ * ```ts
799
+ * const prewarmer = createSandboxPrewarmer(shell, {
800
+ * claim: createD1PrewarmClaimStore(env.DB),
801
+ * mode: 'create-or-resume',
802
+ * })
803
+ * ```
804
+ */
805
+ declare function createD1PrewarmClaimStore(db: PrewarmClaimD1Like, options?: D1PrewarmClaimStoreOptions): {
806
+ acquire(key: string, ttlSeconds: number): Promise<boolean>;
807
+ release(key: string): Promise<void>;
808
+ isHeld(key: string): Promise<boolean>;
809
+ };
810
+
730
811
  /** Define client credentials for accessing the sandbox environment with API key and base URL */
731
812
  interface SandboxClientCredentials {
732
813
  apiKey: string;
@@ -1228,4 +1309,4 @@ declare function isTerminalPromptEvent(event: unknown): boolean;
1228
1309
  /** Resolve the interactive question text from a structured event or return null if none found */
1229
1310
  declare function detectInteractiveQuestion(event: unknown): string | null;
1230
1311
 
1231
- export { type AppToolDescriptor, type AuthenticatedSandboxUser, type BuildAppToolMcpServersOptions, type BuildSandboxToolFileMountsOptions, DEFAULT_SANDBOX_RESOURCES, type DriveSandboxTurnOptions, ENV_TOTAL_MAX_BYTES, ENV_VALUE_MAX_BYTES, type EnsureWorkspaceSandboxOptions, type LivenessProbeConfig, type MemberSyncSeam, type ModelSelection, type ModelSelectionError, type ModelSelectionFailure, type ModelSelectionSource, type Outcome, PROVISION_PAYLOAD_MAX_BYTES, type PeekWorkspaceSandboxOutcome, type PrewarmClaimStore, type PrewarmDecision, type PrewarmEvent, type PrewarmOutcome, type PrewarmResult, type ProfileComposeOptions, type PromptInputPart, type ProviderResolutionConfig, type ProvisionPayloadSections, type ProvisionProfileSection, type ResolveSandboxClientCredentialsOptions, type ResolvedModel, type SandboxApiCredentials, type SandboxBuildContext, type SandboxClientCredentials, type SandboxCredentialEnvironment, type SandboxExecChannel, type SandboxExecOptions, type SandboxFileBytesOutcome, type SandboxFileSizeOutcome, SandboxModelResolutionError, type SandboxPermissionLevel, type SandboxPrewarmScope, type SandboxPrewarmer, type SandboxPrewarmerOptions, type SandboxReadiness, SandboxRecoveryFailedError, type SandboxRecoveryPhase, type SandboxResourceConfig, type SandboxRestoreSpec, SandboxRuntimeAuthRefreshError, type SandboxRuntimeConfig, type SandboxRuntimeConnection, type SandboxScope, type SandboxStepTransition, type SandboxTerminalTokenOptions, type SandboxTerminalTokenResult, type SandboxTerminalTokenSubject, type SandboxTerminalWsMatch, type SandboxToolPathOptions, type SandboxToolSpec, type ScopedTokenResult, type SecretStore, type StoppedSandboxResumeFailure, type StoppedSandboxResumeRecovery, type StreamSandboxPromptOptions, type TerminalProxyIdentity, type TerminalUpgradeResponseLike, type WorkspaceSandboxConnectionArgs, type WorkspaceSandboxConnectionHandlerOptions, type WorkspaceSandboxEnsureContext, type WorkspaceSandboxInstanceLike, type WorkspaceSandboxManager, type WorkspaceSandboxManagerOptions, type WorkspaceSandboxRuntimeProxyArgs, type WorkspaceSandboxRuntimeProxyHandlerOptions, type WorkspaceSandboxTerminalUpgradeHandlerOptions, type WriteProfileFilesOptions, assertEnvWithinLimits, assertProvisionPayloadWithinCap, attachReasoningEffort, bearerSubprotocolToken, bearerToken, buildAppToolMcpServers, buildSandboxRuntimeProxyHeaders, buildSandboxToolFileMounts, buildSandboxToolPathSetupScript, classifySeveredStream, collectSandboxPromptText, createSandboxPrewarmer, createSandboxTerminalToken, createWorkspaceSandboxConnectionHandler, createWorkspaceSandboxManager, createWorkspaceSandboxRuntimeProxyHandler, createWorkspaceSandboxTerminalUpgradeHandler, deferredCorpusHash, deleteSecret, detectInteractiveQuestion, driveSandboxTurn, encodeSandboxRuntimePath, ensureWorkspaceSandbox, flattenHistory, getClient, isSandboxTerminalWsUpgrade, isTerminalPromptEvent, matchSandboxTerminalWsPath, mergeExtraMcp, mergeHistoryIntoParts, mintSandboxScopedToken, mintTerminalProxyToken, peekWorkspaceSandbox, readSandboxBinaryBytes, readSecret, requireTransportableModel, resetClientCache, resolveModel, resolveModelSelection, resolveSandboxClientCredentials, runSandboxPrompt, runSandboxToolPathSetup, sandboxSidecarProxyUrl, sandboxToolBinDir, sandboxToolPath, sandboxToolRootDir, secretStoreFromClient, selectedBearerSubprotocol, shellQuote, splitDeferredProfileFiles, statSandboxFileSize, storeSecret, streamSandboxPrompt, syncSandboxMemberAdd, syncSandboxMemberRemove, syncSandboxMemberRole, terminalTokenFromRequest, terminalUpgradeSubprotocolEcho, verifySandboxTerminalToken, verifyTerminalProxyToken, writeProfileFilesToBox };
1312
+ export { type AppToolDescriptor, type AuthenticatedSandboxUser, type BuildAppToolMcpServersOptions, type BuildSandboxToolFileMountsOptions, type D1PrewarmClaimStoreOptions, DEFAULT_PREWARM_CLAIM_TABLE, DEFAULT_SANDBOX_RESOURCES, type DriveSandboxTurnOptions, ENV_TOTAL_MAX_BYTES, ENV_VALUE_MAX_BYTES, type EnsureWorkspaceSandboxOptions, type LivenessProbeConfig, type MemberSyncSeam, type ModelSelection, type ModelSelectionError, type ModelSelectionFailure, type ModelSelectionSource, type Outcome, PREWARM_CLAIM_TABLE_DDL, PROVISION_PAYLOAD_MAX_BYTES, type PeekWorkspaceSandboxOutcome, type PrewarmClaimD1Like, type PrewarmClaimStore, type PrewarmDecision, type PrewarmEvent, type PrewarmOutcome, type PrewarmResult, type ProfileComposeOptions, type PromptInputPart, type ProviderResolutionConfig, type ProvisionPayloadSections, type ProvisionProfileSection, type ResolveSandboxClientCredentialsOptions, type ResolvedModel, type SandboxApiCredentials, type SandboxBuildContext, type SandboxClientCredentials, type SandboxCredentialEnvironment, type SandboxExecChannel, type SandboxExecOptions, type SandboxFileBytesOutcome, type SandboxFileSizeOutcome, SandboxModelResolutionError, type SandboxPermissionLevel, type SandboxPrewarmScope, type SandboxPrewarmer, type SandboxPrewarmerOptions, type SandboxReadiness, SandboxRecoveryFailedError, type SandboxRecoveryPhase, type SandboxResourceConfig, type SandboxRestoreSpec, SandboxRuntimeAuthRefreshError, type SandboxRuntimeConfig, type SandboxRuntimeConnection, type SandboxScope, type SandboxStepTransition, type SandboxTerminalTokenOptions, type SandboxTerminalTokenResult, type SandboxTerminalTokenSubject, type SandboxTerminalWsMatch, type SandboxToolPathOptions, type SandboxToolSpec, type ScopedTokenResult, type SecretStore, type StoppedSandboxResumeFailure, type StoppedSandboxResumeRecovery, type StreamSandboxPromptOptions, type TerminalProxyIdentity, type TerminalUpgradeResponseLike, type WorkspaceSandboxConnectionArgs, type WorkspaceSandboxConnectionHandlerOptions, type WorkspaceSandboxEnsureContext, type WorkspaceSandboxInstanceLike, type WorkspaceSandboxManager, type WorkspaceSandboxManagerOptions, type WorkspaceSandboxRuntimeProxyArgs, type WorkspaceSandboxRuntimeProxyHandlerOptions, type WorkspaceSandboxTerminalUpgradeHandlerOptions, type WriteProfileFilesOptions, assertEnvWithinLimits, assertProvisionPayloadWithinCap, attachReasoningEffort, bearerSubprotocolToken, bearerToken, buildAppToolMcpServers, buildSandboxRuntimeProxyHeaders, buildSandboxToolFileMounts, buildSandboxToolPathSetupScript, classifySeveredStream, collectSandboxPromptText, createD1PrewarmClaimStore, createSandboxPrewarmer, createSandboxTerminalToken, createWorkspaceSandboxConnectionHandler, createWorkspaceSandboxManager, createWorkspaceSandboxRuntimeProxyHandler, createWorkspaceSandboxTerminalUpgradeHandler, deferredCorpusHash, deleteSecret, detectInteractiveQuestion, driveSandboxTurn, encodeSandboxRuntimePath, ensureWorkspaceSandbox, flattenHistory, getClient, isSandboxTerminalWsUpgrade, isTerminalPromptEvent, matchSandboxTerminalWsPath, mergeExtraMcp, mergeHistoryIntoParts, mintSandboxScopedToken, mintTerminalProxyToken, peekWorkspaceSandbox, readSandboxBinaryBytes, readSecret, requireTransportableModel, resetClientCache, resolveModel, resolveModelSelection, resolveSandboxClientCredentials, runSandboxPrompt, runSandboxToolPathSetup, sandboxSidecarProxyUrl, sandboxToolBinDir, sandboxToolPath, sandboxToolRootDir, secretStoreFromClient, selectedBearerSubprotocol, shellQuote, splitDeferredProfileFiles, statSandboxFileSize, storeSecret, streamSandboxPrompt, syncSandboxMemberAdd, syncSandboxMemberRemove, syncSandboxMemberRole, terminalTokenFromRequest, terminalUpgradeSubprotocolEcho, verifySandboxTerminalToken, verifyTerminalProxyToken, writeProfileFilesToBox };
@@ -1,7 +1,9 @@
1
1
  import {
2
+ DEFAULT_PREWARM_CLAIM_TABLE,
2
3
  DEFAULT_SANDBOX_RESOURCES,
3
4
  ENV_TOTAL_MAX_BYTES,
4
5
  ENV_VALUE_MAX_BYTES,
6
+ PREWARM_CLAIM_TABLE_DDL,
5
7
  PROVISION_PAYLOAD_MAX_BYTES,
6
8
  SandboxModelResolutionError,
7
9
  SandboxRecoveryFailedError,
@@ -17,6 +19,7 @@ import {
17
19
  buildSandboxToolPathSetupScript,
18
20
  classifySeveredStream,
19
21
  collectSandboxPromptText,
22
+ createD1PrewarmClaimStore,
20
23
  createSandboxPrewarmer,
21
24
  createSandboxTerminalToken,
22
25
  createWorkspaceSandboxConnectionHandler,
@@ -67,7 +70,7 @@ import {
67
70
  verifySandboxTerminalToken,
68
71
  verifyTerminalProxyToken,
69
72
  writeProfileFilesToBox
70
- } from "../chunk-BAC2B2KI.js";
73
+ } from "../chunk-7WXG4ZFP.js";
71
74
  import "../chunk-LWSJK546.js";
72
75
  import "../chunk-CQZSAR77.js";
73
76
  import "../chunk-ICOHEZK6.js";
@@ -76,9 +79,11 @@ import "../chunk-YEFFHORB.js";
76
79
  import "../chunk-S5SRJJQG.js";
77
80
  import "../chunk-JML7WKWU.js";
78
81
  export {
82
+ DEFAULT_PREWARM_CLAIM_TABLE,
79
83
  DEFAULT_SANDBOX_RESOURCES,
80
84
  ENV_TOTAL_MAX_BYTES,
81
85
  ENV_VALUE_MAX_BYTES,
86
+ PREWARM_CLAIM_TABLE_DDL,
82
87
  PROVISION_PAYLOAD_MAX_BYTES,
83
88
  SandboxModelResolutionError,
84
89
  SandboxRecoveryFailedError,
@@ -94,6 +99,7 @@ export {
94
99
  buildSandboxToolPathSetupScript,
95
100
  classifySeveredStream,
96
101
  collectSandboxPromptText,
102
+ createD1PrewarmClaimStore,
97
103
  createSandboxPrewarmer,
98
104
  createSandboxTerminalToken,
99
105
  createWorkspaceSandboxConnectionHandler,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.44.30",
3
+ "version": "0.44.32",
4
4
  "packageManager": "pnpm@10.33.4",
5
5
  "description": "Application-shell framework for Tangle agent products: a bounded tool loop, the structured agent→app tool side channel, integration-hub client, per-workspace billing, and crypto — composed over the Tangle agent substrate through typed seams.",
6
6
  "keywords": [