@skrr-ai/cli 0.1.180 → 0.1.182

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.
Files changed (32) hide show
  1. package/dist/commands/agents/always-on/recovery-review.d.ts +17 -0
  2. package/dist/commands/agents/always-on/recovery-review.js +81 -3
  3. package/dist/commands/agents/always-on/status.js +10 -1
  4. package/dist/commands/agents/delete.js +10 -0
  5. package/dist/commands/balance/statement.d.ts +6 -0
  6. package/dist/commands/balance/statement.js +49 -25
  7. package/dist/commands/duties/delete.js +9 -0
  8. package/dist/lib/agent-model-check.d.ts +19 -0
  9. package/dist/lib/agent-model-check.js +10 -20
  10. package/dist/lib/balance.d.ts +10 -0
  11. package/dist/lib/credential-resolver.d.ts +1 -0
  12. package/dist/lib/credential-resolver.js +5 -1
  13. package/dist/lib/duties.d.ts +5 -1
  14. package/dist/lib/duties.js +42 -13
  15. package/dist/lib/duty-loop-status.js +20 -0
  16. package/dist/lib/first-party-harness-broker.d.ts +0 -10
  17. package/dist/lib/first-party-harness-broker.js +22 -50
  18. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.json +1 -297
  19. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/managedWorkRuntime.d.ts +40 -0
  20. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/managedWorkRuntime.js +94 -0
  21. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/telemetryRedaction.js +6 -2
  22. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/managedWorkRuntime.d.ts +40 -0
  23. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/managedWorkRuntime.js +56 -0
  24. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/telemetryRedaction.js +35 -12
  25. package/dist/node_modules/@skrr-ai/auth-core/package.json +5 -0
  26. package/dist/node_modules/@skrr-ai/data-provider/index.js +11247 -11173
  27. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.d.ts +28 -1
  28. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.js +40 -11
  29. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.d.ts +28 -1
  30. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.js +73 -17
  31. package/oclif.manifest.json +1 -1
  32. package/package.json +2 -2
@@ -37,6 +37,12 @@ export interface ManagedInferenceRequestEnvelope {
37
37
  maxResponseBytes: number;
38
38
  allowStreaming: boolean;
39
39
  allowPromptCaching: boolean;
40
+ /**
41
+ * The longer Claude cache-write lifetime the lease's reservation floor priced (OSK-24701), on a
42
+ * caching envelope only. Absent is the 5-minute default. A broker that predates it ignores it,
43
+ * which only lowers what a request may cost.
44
+ */
45
+ cacheWriteLifetime?: '1h';
40
46
  allowedReasoningEfforts: string[];
41
47
  /**
42
48
  * Server-authoritative preferred effort when the caller did not choose one.
@@ -119,6 +125,8 @@ export interface ManagedInferenceBrokerOptions {
119
125
  * {@link ManagedInferenceBrokerSession.localRefusal}.
120
126
  */
121
127
  maxRequestBytes?: number;
128
+ /** Extra per-invocation ceiling for bounded daemon manager roles. */
129
+ maxModelRequests?: number;
122
130
  /**
123
131
  * OSK-3901 — remaining lease lifetime, in ms, at the moment the broker starts.
124
132
  *
@@ -168,7 +176,8 @@ export interface ManagedInferenceBrokerOptions {
168
176
  * markers and cannot be told not to (Claude Code, OSK-24457): under a lease
169
177
  * that does NOT allow caching every marker is removed; under a Claude lease
170
178
  * that does (OSK-24595) a `ttl` other than `5m` is removed (a 1-hour write is
171
- * 2x input and no reservation prices it), and a request still outside the
179
+ * 2x input), unless the envelope names that lifetime (`cacheWriteLifetime`,
180
+ * OSK-24701) and the reservation priced it, and a request still outside the
172
181
  * contract after that is forwarded uncached. Stripping can only lower what a
173
182
  * request costs. Every other prompt-cache field is still refused.
174
183
  */
@@ -183,6 +192,7 @@ export type ManagedInferenceBrokerTransport = 'unix-socket' | 'loopback-tcp';
183
192
  export interface ManagedInferenceEndpoint {
184
193
  /** `http://127.0.0.1:<port>`, no path. */
185
194
  readonly origin: string;
195
+ readonly maxModelRequests?: number;
186
196
  /** The lease's upstream dialect family, so a caller can pick the client wire. */
187
197
  readonly upstreamProvider: ManagedInferenceModelScope['upstreamProvider'] | null;
188
198
  bearerToken(): string;
@@ -338,6 +348,13 @@ export interface ManagedInputEnvelope {
338
348
  * `undefined`, never a guess.
339
349
  */
340
350
  export declare function parseManagedInputEnvelope(value: string | undefined): ManagedInputEnvelope | undefined;
351
+ /**
352
+ * The endpoints a scoped request may be forwarded under, every one of them for every lease: the
353
+ * broker approves an endpoint, never an (endpoint, model) pair, because whether a dialect may reach
354
+ * the leased model is the relay's decision (OSK-24536). Exported for the broker's spec only, like
355
+ * `MANAGED_UPSTREAM_ACCOUNTING`.
356
+ */
357
+ export declare const MANAGED_FORWARDED_PATHS: readonly string[];
341
358
  /**
342
359
  * OSK-24521 — the status a request gets when the host's transport had no credential to send it
343
360
  * with: 400, the one status the harnesses this answer reaches give up on at once. A credential
@@ -355,6 +372,16 @@ export declare function managedClientModelId(scope: ManagedInferenceModelScope):
355
372
  /** True only for a concrete gateway descriptor; raw provider keys never enter this broker. */
356
373
  export declare function isGatewayCredential(value: unknown): value is Required<Pick<GatewayCredential, 'baseUrl' | 'authToken'>> & GatewayCredential;
357
374
  export declare function isManagedInferenceModelScope(value: unknown): value is ManagedInferenceModelScope;
375
+ /**
376
+ * Every upstream family a lease may name, and the input-token accounting the relay meters it in.
377
+ * A scope naming any other family is not a lease (`isManagedInferenceModelScope`).
378
+ *
379
+ * This is the broker's whole upstream vocabulary, and it decides nothing about dialects: which
380
+ * dialect may reach a model is the relay's one route decision (OSK-24536). Exported, not
381
+ * re-exported from the package index, so the broker's spec iterates it and a family added here
382
+ * joins that spec's every-family, every-endpoint matrix without anyone remembering to.
383
+ */
384
+ export declare const MANAGED_UPSTREAM_ACCOUNTING: Readonly<Record<string, ManagedInferenceInputTokenAccounting['algorithm']>>;
358
385
  /**
359
386
  * Build the public, session-scoped OverSky relay from a non-secret server
360
387
  * model contract. Current servers never deliver a LiteLLM virtual key to the
@@ -23,10 +23,12 @@ __export(managed_inference_broker_exports, {
23
23
  INFERENCE_BROKER_ORIGIN: () => INFERENCE_BROKER_ORIGIN,
24
24
  INFERENCE_BROKER_SOCKET_ENV: () => INFERENCE_BROKER_SOCKET_ENV,
25
25
  LOOPBACK_BROKER_NO_PROXY_HOSTS: () => LOOPBACK_BROKER_NO_PROXY_HOSTS,
26
+ MANAGED_FORWARDED_PATHS: () => MANAGED_FORWARDED_PATHS,
26
27
  MANAGED_INPUT_ENVELOPE_ENV: () => MANAGED_INPUT_ENVELOPE_ENV,
27
28
  MANAGED_PROMPT_CACHING_ENV: () => MANAGED_PROMPT_CACHING_ENV,
28
29
  MANAGED_SESSION_ENV: () => MANAGED_SESSION_ENV,
29
30
  MANAGED_STATUS_PATH: () => MANAGED_STATUS_PATH,
31
+ MANAGED_UPSTREAM_ACCOUNTING: () => MANAGED_UPSTREAM_ACCOUNTING,
30
32
  buildManagedInferenceRelayCredential: () => buildManagedInferenceRelayCredential,
31
33
  classifyLeaseRenewalRefusal: () => classifyLeaseRenewalRefusal,
32
34
  inferenceBrokerNoProxyEnv: () => inferenceBrokerNoProxyEnv,
@@ -122,7 +124,7 @@ function parseManagedInputEnvelope(value) {
122
124
  return void 0;
123
125
  return { maxInputTokens: Number(maxInputTokens), algorithm };
124
126
  }
125
- const ALLOWED_PATHS = /* @__PURE__ */ new Set([
127
+ const MANAGED_FORWARDED_PATHS = Object.freeze([
126
128
  "/v1/messages",
127
129
  "/messages",
128
130
  "/v1/chat/completions",
@@ -130,6 +132,7 @@ const ALLOWED_PATHS = /* @__PURE__ */ new Set([
130
132
  "/v1/responses",
131
133
  "/responses"
132
134
  ]);
135
+ const ALLOWED_PATHS = new Set(MANAGED_FORWARDED_PATHS);
133
136
  const ANTHROPIC_MESSAGES_PATHS = /* @__PURE__ */ new Set(["/v1/messages", "/messages"]);
134
137
  const ANTHROPIC_COUNT_TOKENS_PATHS = /* @__PURE__ */ new Set([
135
138
  "/v1/messages/count_tokens",
@@ -217,8 +220,15 @@ function isManagedInputTokenAccounting(value) {
217
220
  const accounting = value;
218
221
  return Boolean(accounting.version === 1 && accounting.mode === "server_authoritative" && ["openai_o200k_json_v1", "utf8_bytes_json_v1"].includes(String(accounting.algorithm)));
219
222
  }
223
+ const MANAGED_UPSTREAM_ACCOUNTING = Object.freeze({
224
+ openai: "openai_o200k_json_v1",
225
+ anthropic: "utf8_bytes_json_v1",
226
+ openrouter: "utf8_bytes_json_v1",
227
+ bedrock: "utf8_bytes_json_v1"
228
+ });
220
229
  function managedAccountingMatchesProvider(upstreamProvider, accounting) {
221
- return upstreamProvider === "openai" && accounting.algorithm === "openai_o200k_json_v1" || ["anthropic", "openrouter", "bedrock"].includes(String(upstreamProvider)) && accounting.algorithm === "utf8_bytes_json_v1";
230
+ const family = String(upstreamProvider);
231
+ return Object.prototype.hasOwnProperty.call(MANAGED_UPSTREAM_ACCOUNTING, family) && MANAGED_UPSTREAM_ACCOUNTING[family] === accounting.algorithm;
222
232
  }
223
233
  function buildManagedInferenceRelayCredential(credential, options) {
224
234
  const sessionId = nonEmpty(options.sessionId);
@@ -306,6 +316,11 @@ async function startManagedInferenceBroker(options) {
306
316
  const envelope = modelScope?.requestEnvelope ?? null;
307
317
  let activeRequests = 0;
308
318
  let totalRequests = 0;
319
+ const maxModelRequests = options.maxModelRequests;
320
+ if (maxModelRequests !== void 0 && (!Number.isSafeInteger(maxModelRequests) || maxModelRequests < 1 || maxModelRequests > 8)) {
321
+ throw new Error("invalid managed work model call limit");
322
+ }
323
+ let admittedModelRequests = 0;
309
324
  const requestStarts = [];
310
325
  const acquireRequestSlot = () => {
311
326
  if (!envelope)
@@ -360,6 +375,12 @@ async function startManagedInferenceBroker(options) {
360
375
  const url = resolveGatewayUrl(gatewayBase, origin, path);
361
376
  try {
362
377
  const body = assertApprovedEnvelope(request.method, path, request.body, modelScope, legacyModel, promptCacheControl);
378
+ if (maxModelRequests !== void 0) {
379
+ if (admittedModelRequests >= maxModelRequests) {
380
+ rejectManagedRequest("Managed work maximum model calls exhausted.");
381
+ }
382
+ admittedModelRequests += 1;
383
+ }
363
384
  const headers = new Headers();
364
385
  for (const [name, value] of Object.entries(request.headers)) {
365
386
  if (FORWARDED_HEADERS.has(name.toLowerCase()))
@@ -542,6 +563,7 @@ async function startManagedInferenceBroker(options) {
542
563
  env: { [MANAGED_SESSION_ENV]: "1", ...leaseEnv },
543
564
  endpoint: {
544
565
  origin: listener.origin,
566
+ ...maxModelRequests === void 0 ? {} : { maxModelRequests },
545
567
  upstreamProvider: modelScope?.upstreamProvider ?? null,
546
568
  bearerToken: () => {
547
569
  if (stopped || !relayToken)
@@ -837,6 +859,10 @@ function isPlainObject(value) {
837
859
  const MAX_OPENAI_CACHE_BREAKPOINTS = 50;
838
860
  const CLAUDE_PROMPT_CACHE_TTL = "5m";
839
861
  const CLAUDE_MAX_CACHE_BREAKPOINTS = 4;
862
+ const CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES = ["1h"];
863
+ function claudeCacheTtls(envelope) {
864
+ return envelope.allowPromptCaching && typeof envelope.cacheWriteLifetime === "string" && CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES.includes(envelope.cacheWriteLifetime) ? [CLAUDE_PROMPT_CACHE_TTL, envelope.cacheWriteLifetime] : [CLAUDE_PROMPT_CACHE_TTL];
865
+ }
840
866
  const CLAUDE_PROMPT_CACHE_UPSTREAMS = ["anthropic", "bedrock"];
841
867
  function managedPromptCacheContract(modelScope) {
842
868
  const model = nonEmpty(modelScope.wireModel)?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, "").toLowerCase();
@@ -850,7 +876,7 @@ function managedPromptCacheContract(modelScope) {
850
876
  function supportsManagedPromptCaching(modelScope) {
851
877
  return managedPromptCacheContract(modelScope) !== null;
852
878
  }
853
- function claudeCacheControlViolation(payload) {
879
+ function claudeCacheControlViolation(payload, ttls = [CLAUDE_PROMPT_CACHE_TTL]) {
854
880
  const controls = objectKeyValues(payload, "cache_control");
855
881
  if (controls.length > CLAUDE_MAX_CACHE_BREAKPOINTS) {
856
882
  return `at most ${CLAUDE_MAX_CACHE_BREAKPOINTS} cache_control breakpoints are allowed`;
@@ -863,15 +889,15 @@ function claudeCacheControlViolation(payload) {
863
889
  }
864
890
  if (control.type !== "ephemeral")
865
891
  return "cache_control type must be ephemeral";
866
- if (control.ttl != null && control.ttl !== CLAUDE_PROMPT_CACHE_TTL) {
867
- return `cache_control ttl must be ${CLAUDE_PROMPT_CACHE_TTL}`;
892
+ if (control.ttl != null && (typeof control.ttl !== "string" || !ttls.includes(control.ttl))) {
893
+ return `cache_control ttl must be ${ttls.join(" or ")}`;
868
894
  }
869
895
  }
870
896
  return null;
871
897
  }
872
- function normalizeClaudeCacheTtl(payload) {
898
+ function normalizeClaudeCacheTtl(payload, ttls = [CLAUDE_PROMPT_CACHE_TTL]) {
873
899
  for (const control of objectKeyValues(payload, "cache_control")) {
874
- if (isPlainObject(control) && control.ttl != null && control.ttl !== CLAUDE_PROMPT_CACHE_TTL) {
900
+ if (isPlainObject(control) && control.ttl != null && (typeof control.ttl !== "string" || !ttls.includes(control.ttl))) {
875
901
  delete control.ttl;
876
902
  }
877
903
  }
@@ -888,12 +914,13 @@ function enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheCo
888
914
  if (openAICacheFields) {
889
915
  rejectManagedRequest("managed inference broker denied a prompt cache field Claude caching does not use");
890
916
  }
917
+ const ttls = claudeCacheTtls(envelope);
891
918
  if (promptCacheControl === "strip") {
892
- normalizeClaudeCacheTtl(payload);
893
- if (claudeCacheControlViolation(payload))
919
+ normalizeClaudeCacheTtl(payload, ttls);
920
+ if (claudeCacheControlViolation(payload, ttls))
894
921
  deleteObjectKey(payload, "cache_control");
895
922
  }
896
- const violation = claudeCacheControlViolation(payload);
923
+ const violation = claudeCacheControlViolation(payload, ttls);
897
924
  if (violation) {
898
925
  rejectManagedRequest(`managed inference broker denied prompt caching: ${violation}`);
899
926
  }
@@ -942,7 +969,7 @@ function isManagedRequestEnvelope(value) {
942
969
  const envelope = value;
943
970
  const boundedPositiveInteger = (candidate, max) => Number.isSafeInteger(candidate) && Number(candidate) > 0 && Number(candidate) <= max;
944
971
  const allowedEfforts = /* @__PURE__ */ new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
945
- return Boolean(boundedPositiveInteger(envelope.maxInputBytes, 8 * 1024 * 1024) && boundedPositiveInteger(envelope.maxInputTokens, 1e6) && boundedPositiveInteger(envelope.maxOutputTokens, 1e6) && boundedPositiveInteger(envelope.maxReasoningTokens, 1e6) && boundedPositiveInteger(envelope.maxConcurrentRequests, 64) && boundedPositiveInteger(envelope.maxRequestsPerMinute, 1e4) && boundedPositiveInteger(envelope.maxTotalRequests, 1e5) && boundedPositiveInteger(envelope.maxResponseBytes, 128 * 1024 * 1024) && typeof envelope.allowStreaming === "boolean" && typeof envelope.allowPromptCaching === "boolean" && Array.isArray(envelope.allowedReasoningEfforts) && envelope.allowedReasoningEfforts.length > 0 && envelope.allowedReasoningEfforts.every((effort) => allowedEfforts.has(effort)) && (envelope.defaultReasoningEffort == null || allowedEfforts.has(envelope.defaultReasoningEffort) && envelope.allowedReasoningEfforts.includes(envelope.defaultReasoningEffort)) && (envelope.selectedReasoningEffort == null ? envelope.requestedReasoningEffort == null && envelope.reasoningSelectionSource == null : allowedEfforts.has(envelope.selectedReasoningEffort) && envelope.allowedReasoningEfforts.includes(envelope.selectedReasoningEffort) && (envelope.reasoningSelectionSource === "request" || envelope.reasoningSelectionSource === "policy_default")) && (envelope.reasoningSelectionSource !== "request" || envelope.requestedReasoningEffort === envelope.selectedReasoningEffort) && (envelope.reasoningSelectionSource !== "policy_default" || envelope.defaultReasoningEffort === envelope.selectedReasoningEffort));
972
+ return Boolean(boundedPositiveInteger(envelope.maxInputBytes, 8 * 1024 * 1024) && boundedPositiveInteger(envelope.maxInputTokens, 1e6) && boundedPositiveInteger(envelope.maxOutputTokens, 1e6) && boundedPositiveInteger(envelope.maxReasoningTokens, 1e6) && boundedPositiveInteger(envelope.maxConcurrentRequests, 64) && boundedPositiveInteger(envelope.maxRequestsPerMinute, 1e4) && boundedPositiveInteger(envelope.maxTotalRequests, 1e5) && boundedPositiveInteger(envelope.maxResponseBytes, 128 * 1024 * 1024) && typeof envelope.allowStreaming === "boolean" && typeof envelope.allowPromptCaching === "boolean" && (envelope.cacheWriteLifetime == null || envelope.allowPromptCaching === true && CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES.includes(envelope.cacheWriteLifetime)) && Array.isArray(envelope.allowedReasoningEfforts) && envelope.allowedReasoningEfforts.length > 0 && envelope.allowedReasoningEfforts.every((effort) => allowedEfforts.has(effort)) && (envelope.defaultReasoningEffort == null || allowedEfforts.has(envelope.defaultReasoningEffort) && envelope.allowedReasoningEfforts.includes(envelope.defaultReasoningEffort)) && (envelope.selectedReasoningEffort == null ? envelope.requestedReasoningEffort == null && envelope.reasoningSelectionSource == null : allowedEfforts.has(envelope.selectedReasoningEffort) && envelope.allowedReasoningEfforts.includes(envelope.selectedReasoningEffort) && (envelope.reasoningSelectionSource === "request" || envelope.reasoningSelectionSource === "policy_default")) && (envelope.reasoningSelectionSource !== "request" || envelope.requestedReasoningEffort === envelope.selectedReasoningEffort) && (envelope.reasoningSelectionSource !== "policy_default" || envelope.defaultReasoningEffort === envelope.selectedReasoningEffort));
946
973
  }
947
974
  function constantTimeStringEqual(value, expected) {
948
975
  if (typeof value !== "string")
@@ -1014,10 +1041,12 @@ async function* responseBody(response, maxBytes, onComplete = () => {
1014
1041
  INFERENCE_BROKER_ORIGIN,
1015
1042
  INFERENCE_BROKER_SOCKET_ENV,
1016
1043
  LOOPBACK_BROKER_NO_PROXY_HOSTS,
1044
+ MANAGED_FORWARDED_PATHS,
1017
1045
  MANAGED_INPUT_ENVELOPE_ENV,
1018
1046
  MANAGED_PROMPT_CACHING_ENV,
1019
1047
  MANAGED_SESSION_ENV,
1020
1048
  MANAGED_STATUS_PATH,
1049
+ MANAGED_UPSTREAM_ACCOUNTING,
1021
1050
  buildManagedInferenceRelayCredential,
1022
1051
  classifyLeaseRenewalRefusal,
1023
1052
  inferenceBrokerNoProxyEnv,
@@ -37,6 +37,12 @@ export interface ManagedInferenceRequestEnvelope {
37
37
  maxResponseBytes: number;
38
38
  allowStreaming: boolean;
39
39
  allowPromptCaching: boolean;
40
+ /**
41
+ * The longer Claude cache-write lifetime the lease's reservation floor priced (OSK-24701), on a
42
+ * caching envelope only. Absent is the 5-minute default. A broker that predates it ignores it,
43
+ * which only lowers what a request may cost.
44
+ */
45
+ cacheWriteLifetime?: '1h';
40
46
  allowedReasoningEfforts: string[];
41
47
  /**
42
48
  * Server-authoritative preferred effort when the caller did not choose one.
@@ -119,6 +125,8 @@ export interface ManagedInferenceBrokerOptions {
119
125
  * {@link ManagedInferenceBrokerSession.localRefusal}.
120
126
  */
121
127
  maxRequestBytes?: number;
128
+ /** Extra per-invocation ceiling for bounded daemon manager roles. */
129
+ maxModelRequests?: number;
122
130
  /**
123
131
  * OSK-3901 — remaining lease lifetime, in ms, at the moment the broker starts.
124
132
  *
@@ -168,7 +176,8 @@ export interface ManagedInferenceBrokerOptions {
168
176
  * markers and cannot be told not to (Claude Code, OSK-24457): under a lease
169
177
  * that does NOT allow caching every marker is removed; under a Claude lease
170
178
  * that does (OSK-24595) a `ttl` other than `5m` is removed (a 1-hour write is
171
- * 2x input and no reservation prices it), and a request still outside the
179
+ * 2x input), unless the envelope names that lifetime (`cacheWriteLifetime`,
180
+ * OSK-24701) and the reservation priced it, and a request still outside the
172
181
  * contract after that is forwarded uncached. Stripping can only lower what a
173
182
  * request costs. Every other prompt-cache field is still refused.
174
183
  */
@@ -183,6 +192,7 @@ export type ManagedInferenceBrokerTransport = 'unix-socket' | 'loopback-tcp';
183
192
  export interface ManagedInferenceEndpoint {
184
193
  /** `http://127.0.0.1:<port>`, no path. */
185
194
  readonly origin: string;
195
+ readonly maxModelRequests?: number;
186
196
  /** The lease's upstream dialect family, so a caller can pick the client wire. */
187
197
  readonly upstreamProvider: ManagedInferenceModelScope['upstreamProvider'] | null;
188
198
  bearerToken(): string;
@@ -338,6 +348,13 @@ export interface ManagedInputEnvelope {
338
348
  * `undefined`, never a guess.
339
349
  */
340
350
  export declare function parseManagedInputEnvelope(value: string | undefined): ManagedInputEnvelope | undefined;
351
+ /**
352
+ * The endpoints a scoped request may be forwarded under, every one of them for every lease: the
353
+ * broker approves an endpoint, never an (endpoint, model) pair, because whether a dialect may reach
354
+ * the leased model is the relay's decision (OSK-24536). Exported for the broker's spec only, like
355
+ * `MANAGED_UPSTREAM_ACCOUNTING`.
356
+ */
357
+ export declare const MANAGED_FORWARDED_PATHS: readonly string[];
341
358
  /**
342
359
  * OSK-24521 — the status a request gets when the host's transport had no credential to send it
343
360
  * with: 400, the one status the harnesses this answer reaches give up on at once. A credential
@@ -355,6 +372,16 @@ export declare function managedClientModelId(scope: ManagedInferenceModelScope):
355
372
  /** True only for a concrete gateway descriptor; raw provider keys never enter this broker. */
356
373
  export declare function isGatewayCredential(value: unknown): value is Required<Pick<GatewayCredential, 'baseUrl' | 'authToken'>> & GatewayCredential;
357
374
  export declare function isManagedInferenceModelScope(value: unknown): value is ManagedInferenceModelScope;
375
+ /**
376
+ * Every upstream family a lease may name, and the input-token accounting the relay meters it in.
377
+ * A scope naming any other family is not a lease (`isManagedInferenceModelScope`).
378
+ *
379
+ * This is the broker's whole upstream vocabulary, and it decides nothing about dialects: which
380
+ * dialect may reach a model is the relay's one route decision (OSK-24536). Exported, not
381
+ * re-exported from the package index, so the broker's spec iterates it and a family added here
382
+ * joins that spec's every-family, every-endpoint matrix without anyone remembering to.
383
+ */
384
+ export declare const MANAGED_UPSTREAM_ACCOUNTING: Readonly<Record<string, ManagedInferenceInputTokenAccounting['algorithm']>>;
358
385
  /**
359
386
  * Build the public, session-scoped OverSky relay from a non-secret server
360
387
  * model contract. Current servers never deliver a LiteLLM virtual key to the
@@ -30,7 +30,9 @@ const CURRENT_OPENAI_CACHE_MODELS = new Set([
30
30
  export function supportsOpenAIExplicitPromptCache(modelId) {
31
31
  if (typeof modelId !== 'string')
32
32
  return false;
33
- const model = modelId.trim().toLowerCase()
33
+ const model = modelId
34
+ .trim()
35
+ .toLowerCase()
34
36
  .replace(/^(?:openai\/|(?:(?:bedrock_mantle|bedrock|amazon-bedrock)\/)?openai\.)/, '');
35
37
  return /(?:^|[/.])gpt-5\.6(?:-|$)/.test(model) || CURRENT_OPENAI_CACHE_MODELS.has(model);
36
38
  }
@@ -163,7 +165,13 @@ export function parseManagedInputEnvelope(value) {
163
165
  return undefined;
164
166
  return { maxInputTokens: Number(maxInputTokens), algorithm };
165
167
  }
166
- const ALLOWED_PATHS = new Set([
168
+ /**
169
+ * The endpoints a scoped request may be forwarded under, every one of them for every lease: the
170
+ * broker approves an endpoint, never an (endpoint, model) pair, because whether a dialect may reach
171
+ * the leased model is the relay's decision (OSK-24536). Exported for the broker's spec only, like
172
+ * `MANAGED_UPSTREAM_ACCOUNTING`.
173
+ */
174
+ export const MANAGED_FORWARDED_PATHS = Object.freeze([
167
175
  '/v1/messages',
168
176
  '/messages',
169
177
  '/v1/chat/completions',
@@ -171,6 +179,7 @@ const ALLOWED_PATHS = new Set([
171
179
  '/v1/responses',
172
180
  '/responses',
173
181
  ]);
182
+ const ALLOWED_PATHS = new Set(MANAGED_FORWARDED_PATHS);
174
183
  const ANTHROPIC_MESSAGES_PATHS = new Set(['/v1/messages', '/messages']);
175
184
  /**
176
185
  * Anthropic's token-counting route. Claude Code calls it (`?beta=true`) to size
@@ -309,10 +318,25 @@ function isManagedInputTokenAccounting(value) {
309
318
  accounting.mode === 'server_authoritative' &&
310
319
  ['openai_o200k_json_v1', 'utf8_bytes_json_v1'].includes(String(accounting.algorithm)));
311
320
  }
321
+ /**
322
+ * Every upstream family a lease may name, and the input-token accounting the relay meters it in.
323
+ * A scope naming any other family is not a lease (`isManagedInferenceModelScope`).
324
+ *
325
+ * This is the broker's whole upstream vocabulary, and it decides nothing about dialects: which
326
+ * dialect may reach a model is the relay's one route decision (OSK-24536). Exported, not
327
+ * re-exported from the package index, so the broker's spec iterates it and a family added here
328
+ * joins that spec's every-family, every-endpoint matrix without anyone remembering to.
329
+ */
330
+ export const MANAGED_UPSTREAM_ACCOUNTING = Object.freeze({
331
+ openai: 'openai_o200k_json_v1',
332
+ anthropic: 'utf8_bytes_json_v1',
333
+ openrouter: 'utf8_bytes_json_v1',
334
+ bedrock: 'utf8_bytes_json_v1',
335
+ });
312
336
  function managedAccountingMatchesProvider(upstreamProvider, accounting) {
313
- return ((upstreamProvider === 'openai' && accounting.algorithm === 'openai_o200k_json_v1') ||
314
- (['anthropic', 'openrouter', 'bedrock'].includes(String(upstreamProvider)) &&
315
- accounting.algorithm === 'utf8_bytes_json_v1'));
337
+ const family = String(upstreamProvider);
338
+ return (Object.prototype.hasOwnProperty.call(MANAGED_UPSTREAM_ACCOUNTING, family) &&
339
+ MANAGED_UPSTREAM_ACCOUNTING[family] === accounting.algorithm);
316
340
  }
317
341
  /**
318
342
  * Build the public, session-scoped OverSky relay from a non-secret server
@@ -432,6 +456,11 @@ export async function startManagedInferenceBroker(options) {
432
456
  const envelope = modelScope?.requestEnvelope ?? null;
433
457
  let activeRequests = 0;
434
458
  let totalRequests = 0;
459
+ const maxModelRequests = options.maxModelRequests;
460
+ if (maxModelRequests !== undefined && (!Number.isSafeInteger(maxModelRequests) || maxModelRequests < 1 || maxModelRequests > 8)) {
461
+ throw new Error('invalid managed work model call limit');
462
+ }
463
+ let admittedModelRequests = 0;
435
464
  const requestStarts = [];
436
465
  const acquireRequestSlot = () => {
437
466
  if (!envelope)
@@ -510,6 +539,12 @@ export async function startManagedInferenceBroker(options) {
510
539
  const url = resolveGatewayUrl(gatewayBase, origin, path);
511
540
  try {
512
541
  const body = assertApprovedEnvelope(request.method, path, request.body, modelScope, legacyModel, promptCacheControl);
542
+ if (maxModelRequests !== undefined) {
543
+ if (admittedModelRequests >= maxModelRequests) {
544
+ rejectManagedRequest('Managed work maximum model calls exhausted.');
545
+ }
546
+ admittedModelRequests += 1;
547
+ }
513
548
  const headers = new Headers();
514
549
  for (const [name, value] of Object.entries(request.headers)) {
515
550
  if (FORWARDED_HEADERS.has(name.toLowerCase()))
@@ -767,6 +802,7 @@ export async function startManagedInferenceBroker(options) {
767
802
  env: { [MANAGED_SESSION_ENV]: '1', ...leaseEnv },
768
803
  endpoint: {
769
804
  origin: listener.origin,
805
+ ...(maxModelRequests === undefined ? {} : { maxModelRequests }),
770
806
  upstreamProvider: modelScope?.upstreamProvider ?? null,
771
807
  bearerToken: () => {
772
808
  if (stopped || !relayToken)
@@ -1130,8 +1166,11 @@ function enforceRequestEnvelope(payload, path, envelope, modelScope, promptCache
1130
1166
  else if (path.endsWith('/messages')) {
1131
1167
  let noThinking = false;
1132
1168
  try {
1133
- noThinking = projectManagedHaiku45None(payload, { model: modelScope.harnessModelId,
1134
- upstreamProvider: modelScope.upstreamProvider, effort: effectiveEffort });
1169
+ noThinking = projectManagedHaiku45None(payload, {
1170
+ model: modelScope.harnessModelId,
1171
+ upstreamProvider: modelScope.upstreamProvider,
1172
+ effort: effectiveEffort,
1173
+ });
1135
1174
  }
1136
1175
  catch {
1137
1176
  rejectManagedRequest('managed Haiku NONE conflicts with thinking or output config');
@@ -1221,6 +1260,16 @@ const MAX_OPENAI_CACHE_BREAKPOINTS = 50;
1221
1260
  */
1222
1261
  const CLAUDE_PROMPT_CACHE_TTL = '5m';
1223
1262
  const CLAUDE_MAX_CACHE_BREAKPOINTS = 4;
1263
+ /** The longer lifetimes an envelope may name (`managedPromptCacheAuthority.js`, OSK-24701). */
1264
+ const CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES = ['1h'];
1265
+ /** The cache `ttl` values a lease admits: 5m, and the longer lifetime its envelope names. */
1266
+ function claudeCacheTtls(envelope) {
1267
+ return envelope.allowPromptCaching &&
1268
+ typeof envelope.cacheWriteLifetime === 'string' &&
1269
+ CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES.includes(envelope.cacheWriteLifetime)
1270
+ ? [CLAUDE_PROMPT_CACHE_TTL, envelope.cacheWriteLifetime]
1271
+ : [CLAUDE_PROMPT_CACHE_TTL];
1272
+ }
1224
1273
  /**
1225
1274
  * The upstreams a Claude caching lease is honoured on. OpenRouter is absent on
1226
1275
  * purpose: it picks the serving endpoint per request, so its cache price and
@@ -1232,7 +1281,8 @@ function managedPromptCacheContract(modelScope) {
1232
1281
  const model = nonEmpty(modelScope.wireModel)
1233
1282
  ?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, '')
1234
1283
  .toLowerCase();
1235
- if (modelScope.upstreamProvider === 'openai' && supportsOpenAIExplicitPromptCache(modelScope.wireModel))
1284
+ if (modelScope.upstreamProvider === 'openai' &&
1285
+ supportsOpenAIExplicitPromptCache(modelScope.wireModel))
1236
1286
  return 'openai';
1237
1287
  if (CLAUDE_PROMPT_CACHE_UPSTREAMS.includes(modelScope.upstreamProvider) &&
1238
1288
  model?.includes('claude')) {
@@ -1244,7 +1294,7 @@ function supportsManagedPromptCaching(modelScope) {
1244
1294
  return managedPromptCacheContract(modelScope) !== null;
1245
1295
  }
1246
1296
  /** Why a request's `cache_control` markers fall outside the Claude contract, or null. */
1247
- function claudeCacheControlViolation(payload) {
1297
+ function claudeCacheControlViolation(payload, ttls = [CLAUDE_PROMPT_CACHE_TTL]) {
1248
1298
  const controls = objectKeyValues(payload, 'cache_control');
1249
1299
  if (controls.length > CLAUDE_MAX_CACHE_BREAKPOINTS) {
1250
1300
  return `at most ${CLAUDE_MAX_CACHE_BREAKPOINTS} cache_control breakpoints are allowed`;
@@ -1257,16 +1307,18 @@ function claudeCacheControlViolation(payload) {
1257
1307
  }
1258
1308
  if (control.type !== 'ephemeral')
1259
1309
  return 'cache_control type must be ephemeral';
1260
- if (control.ttl != null && control.ttl !== CLAUDE_PROMPT_CACHE_TTL) {
1261
- return `cache_control ttl must be ${CLAUDE_PROMPT_CACHE_TTL}`;
1310
+ if (control.ttl != null && (typeof control.ttl !== 'string' || !ttls.includes(control.ttl))) {
1311
+ return `cache_control ttl must be ${ttls.join(' or ')}`;
1262
1312
  }
1263
1313
  }
1264
1314
  return null;
1265
1315
  }
1266
- /** Drop every `ttl` that is not the priced one, so the write falls back to 5 minutes. */
1267
- function normalizeClaudeCacheTtl(payload) {
1316
+ /** Drop every `ttl` the lease did not price, so the write falls back to 5 minutes. */
1317
+ function normalizeClaudeCacheTtl(payload, ttls = [CLAUDE_PROMPT_CACHE_TTL]) {
1268
1318
  for (const control of objectKeyValues(payload, 'cache_control')) {
1269
- if (isPlainObject(control) && control.ttl != null && control.ttl !== CLAUDE_PROMPT_CACHE_TTL) {
1319
+ if (isPlainObject(control) &&
1320
+ control.ttl != null &&
1321
+ (typeof control.ttl !== 'string' || !ttls.includes(control.ttl))) {
1270
1322
  delete control.ttl;
1271
1323
  }
1272
1324
  }
@@ -1299,12 +1351,13 @@ function enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheCo
1299
1351
  if (openAICacheFields) {
1300
1352
  rejectManagedRequest('managed inference broker denied a prompt cache field Claude caching does not use');
1301
1353
  }
1354
+ const ttls = claudeCacheTtls(envelope);
1302
1355
  if (promptCacheControl === 'strip') {
1303
- normalizeClaudeCacheTtl(payload);
1304
- if (claudeCacheControlViolation(payload))
1356
+ normalizeClaudeCacheTtl(payload, ttls);
1357
+ if (claudeCacheControlViolation(payload, ttls))
1305
1358
  deleteObjectKey(payload, 'cache_control');
1306
1359
  }
1307
- const violation = claudeCacheControlViolation(payload);
1360
+ const violation = claudeCacheControlViolation(payload, ttls);
1308
1361
  if (violation) {
1309
1362
  rejectManagedRequest(`managed inference broker denied prompt caching: ${violation}`);
1310
1363
  }
@@ -1370,6 +1423,9 @@ function isManagedRequestEnvelope(value) {
1370
1423
  boundedPositiveInteger(envelope.maxResponseBytes, 128 * 1024 * 1024) &&
1371
1424
  typeof envelope.allowStreaming === 'boolean' &&
1372
1425
  typeof envelope.allowPromptCaching === 'boolean' &&
1426
+ (envelope.cacheWriteLifetime == null ||
1427
+ (envelope.allowPromptCaching === true &&
1428
+ CLAUDE_ENVELOPE_CACHE_WRITE_LIFETIMES.includes(envelope.cacheWriteLifetime))) &&
1373
1429
  Array.isArray(envelope.allowedReasoningEfforts) &&
1374
1430
  envelope.allowedReasoningEfforts.length > 0 &&
1375
1431
  envelope.allowedReasoningEfforts.every((effort) => allowedEfforts.has(effort)) &&
@@ -151482,5 +151482,5 @@
151482
151482
  ]
151483
151483
  }
151484
151484
  },
151485
- "version": "0.1.180"
151485
+ "version": "0.1.182"
151486
151486
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrr-ai/cli",
3
- "version": "0.1.180",
3
+ "version": "0.1.182",
4
4
  "description": "Command-line interface for skrr",
5
5
  "license": "ISC",
6
6
  "author": "skrr",
@@ -707,5 +707,5 @@
707
707
  "engines": {
708
708
  "node": ">=20.0.0"
709
709
  },
710
- "gitHead": "c23b26f74945b3a152360074d4824142634ecbc1"
710
+ "gitHead": "45f32030506256904a55557ab7895112d3228b4f"
711
711
  }