@tangle-network/agent-app 0.60.267 → 0.60.269

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.
@@ -49,7 +49,7 @@ import {
49
49
  createSandboxRunTool,
50
50
  escalationHints,
51
51
  flattenHistory
52
- } from "../chunk-3Q2JI5MQ.js";
52
+ } from "../chunk-UJKWM4UY.js";
53
53
  import "../chunk-4LBCTFBP.js";
54
54
  import "../chunk-DSMGS4IV.js";
55
55
  import "../chunk-5BJHKQ33.js";
@@ -222,6 +222,63 @@ function workersReuseStore() {
222
222
  return createCacheReuseStore(() => storage.open(CACHE_NAME));
223
223
  }
224
224
 
225
+ // src/sandbox/warm-cache.ts
226
+ var MAX_ENTRIES = 500;
227
+ function coloCache() {
228
+ return typeof caches === "undefined" ? void 0 : caches.default;
229
+ }
230
+ function createWarmCache(namespace, options = {}) {
231
+ const useIsolate = options.isolate ?? true;
232
+ const env = options.env;
233
+ const entries = /* @__PURE__ */ new Map();
234
+ const coloKey = (key) => {
235
+ const scope = (typeof env === "function" ? env() : env) ?? "production";
236
+ return new Request(`https://${namespace}/${encodeURIComponent(scope)}/${encodeURIComponent(key)}`);
237
+ };
238
+ const remember = (key, value, expiresAt) => {
239
+ entries.delete(key);
240
+ if (!useIsolate) return;
241
+ const now = Date.now();
242
+ for (const [k, entry] of entries) if (entry.expiresAt <= now) entries.delete(k);
243
+ if (entries.size >= MAX_ENTRIES) {
244
+ const oldest = entries.keys().next().value;
245
+ if (oldest !== void 0) entries.delete(oldest);
246
+ }
247
+ entries.set(key, { value, expiresAt });
248
+ };
249
+ return {
250
+ async read(key) {
251
+ const local = entries.get(key);
252
+ if (local && local.expiresAt > Date.now()) return { value: local.value, source: "isolate" };
253
+ const hit = await coloCache()?.match(coloKey(key)).catch(() => void 0);
254
+ if (!hit) return null;
255
+ const expiresAt = Number(hit.headers.get("x-expires-at"));
256
+ if (!(expiresAt > Date.now())) return null;
257
+ const value = await hit.json().catch(() => void 0);
258
+ if (typeof value !== "object" || value === null || !("v" in value)) return null;
259
+ const stored = value.v;
260
+ remember(key, stored, expiresAt);
261
+ return { value: stored, source: "colo" };
262
+ },
263
+ async write(key, value, ttlMs) {
264
+ const expiresAt = Date.now() + ttlMs;
265
+ remember(key, value, expiresAt);
266
+ await coloCache()?.put(coloKey(key), new Response(JSON.stringify({ v: value }), { headers: {
267
+ "cache-control": `max-age=${Math.max(1, Math.ceil(ttlMs / 1e3))}`,
268
+ "x-expires-at": String(expiresAt)
269
+ } })).catch(() => {
270
+ });
271
+ },
272
+ async forget(key) {
273
+ entries.delete(key);
274
+ await coloCache()?.delete(coloKey(key)).catch(() => false);
275
+ },
276
+ clearIsolate() {
277
+ entries.clear();
278
+ }
279
+ };
280
+ }
281
+
225
282
  // src/sandbox/model.ts
226
283
  function backendModelFields(model) {
227
284
  return {
@@ -3561,6 +3618,7 @@ async function mintSandboxScopedToken(box, options) {
3561
3618
  export {
3562
3619
  traceSandboxPromptEvents,
3563
3620
  createCacheReuseStore,
3621
+ createWarmCache,
3564
3622
  backendModelFields,
3565
3623
  resolveModelSelection,
3566
3624
  resolveModel,
@@ -3662,4 +3720,4 @@ export {
3662
3720
  deleteSecret,
3663
3721
  mintSandboxScopedToken
3664
3722
  };
3665
- //# sourceMappingURL=chunk-3Q2JI5MQ.js.map
3723
+ //# sourceMappingURL=chunk-UJKWM4UY.js.map