@miller-tech/uap 1.73.0 → 1.74.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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Cross-process model-slot lease: a semaphore over the inference backend's
3
+ * concurrent slots, shared via the coordination DB so multiple agents AND
4
+ * multiple `uap` processes hitting the same endpoint never exceed the budget.
5
+ *
6
+ * `withModelSlot(holder, fn)` acquires a slot (waiting when the budget is full),
7
+ * runs `fn`, and releases — the right wrapper around any model call / agent spawn.
8
+ */
9
+ import { CoordinationService } from '../coordination/service.js';
10
+ import { getModelSlotBudget } from './model-slots.js';
11
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
12
+ async function resolveBudget(opts) {
13
+ if (opts.budget && opts.budget > 0)
14
+ return opts.budget;
15
+ return (await getModelSlotBudget(opts.cwd)).budget;
16
+ }
17
+ /**
18
+ * Acquire a model slot, waiting (up to timeoutMs) when the budget is full.
19
+ * Returns a lease id, or null if it timed out (caller may proceed best-effort).
20
+ */
21
+ export async function acquireModelSlot(holder, opts = {}) {
22
+ const service = opts.service ?? new CoordinationService();
23
+ const budget = await resolveBudget(opts);
24
+ const ttlMs = opts.ttlMs ?? 120_000;
25
+ const timeoutMs = opts.timeoutMs ?? 300_000;
26
+ const pollMs = opts.pollMs ?? 200;
27
+ const deadline = Date.now() + timeoutMs;
28
+ for (;;) {
29
+ const leaseId = service.acquireModelSlot(holder, budget, ttlMs);
30
+ if (leaseId !== null)
31
+ return { leaseId, service };
32
+ if (Date.now() >= deadline)
33
+ return { leaseId: null, service }; // fail-open
34
+ await sleep(pollMs);
35
+ }
36
+ }
37
+ /** Run `fn` while holding a model slot (acquire → fn → release). */
38
+ export async function withModelSlot(holder, fn, opts = {}) {
39
+ const { leaseId, service } = await acquireModelSlot(holder, opts);
40
+ try {
41
+ return await fn();
42
+ }
43
+ finally {
44
+ if (leaseId !== null)
45
+ service.releaseModelSlot(leaseId);
46
+ }
47
+ }
48
+ //# sourceMappingURL=model-slot-lease.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-slot-lease.js","sourceRoot":"","sources":["../../src/utils/model-slot-lease.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAgBtD,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEnF,KAAK,UAAU,aAAa,CAAC,IAAsB;IACjD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC;IACvD,OAAO,CAAC,MAAM,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAc,EACd,OAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,mBAAmB,EAAE,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC;IAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IAExC,SAAS,CAAC;QACR,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAChE,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QAClD,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,YAAY;QAC3E,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,EAAoB,EACpB,OAAyB,EAAE;IAE3B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miller-tech/uap",
3
- "version": "1.73.0",
3
+ "version": "1.74.0",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",