@skrr-ai/cli 0.1.171 → 0.1.173

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 (43) hide show
  1. package/dist/commands/harnesses/models.d.ts +12 -0
  2. package/dist/commands/harnesses/models.js +14 -2
  3. package/dist/commands/harnesses/rollouts/grant.d.ts +21 -0
  4. package/dist/commands/harnesses/rollouts/grant.js +56 -0
  5. package/dist/commands/harnesses/rollouts/list.d.ts +24 -0
  6. package/dist/commands/harnesses/rollouts/list.js +87 -0
  7. package/dist/commands/harnesses/rollouts/revoke.d.ts +22 -0
  8. package/dist/commands/harnesses/rollouts/revoke.js +56 -0
  9. package/dist/commands/machines/hosted/exec.d.ts +19 -0
  10. package/dist/commands/machines/hosted/exec.js +59 -5
  11. package/dist/commands/machines/hosted/list.js +8 -1
  12. package/dist/commands/machines/hosted/start.js +10 -1
  13. package/dist/lib/first-party-harness-broker.js +6 -0
  14. package/dist/lib/harness-tiers.d.ts +6 -4
  15. package/dist/lib/harness-tiers.js +12 -10
  16. package/dist/lib/hosted-machines.d.ts +13 -0
  17. package/dist/lib/hosted-machines.js +34 -1
  18. package/dist/lib/provider-rollouts.d.ts +58 -0
  19. package/dist/lib/provider-rollouts.js +23 -0
  20. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.cjs +8 -0
  21. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.d.cts +23 -0
  22. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.json +2381 -0
  23. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessTrust.d.ts +11 -2
  24. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/harnessTrust.js +1 -5
  25. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.d.ts +165 -0
  26. package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.js +132 -0
  27. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessTrust.d.ts +11 -2
  28. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/harnessTrust.js +1 -5
  29. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.d.ts +165 -0
  30. package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.js +203 -0
  31. package/dist/node_modules/@skrr-ai/auth-core/package.json +14 -0
  32. package/dist/node_modules/@skrr-ai/data-provider/index.js +11598 -11591
  33. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.d.ts +1 -1
  34. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.js +4 -0
  35. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.d.ts +58 -1
  36. package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.js +170 -70
  37. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.d.ts +1 -1
  38. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.js +1 -1
  39. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.d.ts +58 -1
  40. package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.js +226 -102
  41. package/dist/node_modules/@skrr-ai/inference-broker/package.json +1 -1
  42. package/oclif.manifest.json +297 -4
  43. package/package.json +5 -2
@@ -60,19 +60,36 @@ export const INFERENCE_BROKER_SOCKET_ENV = 'OVERSKY_INFERENCE_BROKER_SOCKET';
60
60
  * some clients honour `*` only as the entire value.
61
61
  */
62
62
  export function inferenceBrokerNoProxyEnv(env) {
63
+ return noProxyEnvWithHosts(env, [INFERENCE_BROKER_HOST]);
64
+ }
65
+ /**
66
+ * The loopback hosts a `loopback-tcp` broker is reached on. A harness that
67
+ * honours HTTP(S)_PROXY would otherwise send its model traffic, relay token
68
+ * included, to the proxy instead of to this machine (OSK-24457).
69
+ */
70
+ export const LOOPBACK_BROKER_NO_PROXY_HOSTS = ['127.0.0.1', 'localhost'];
71
+ /**
72
+ * {@link inferenceBrokerNoProxyEnv} for any set of hosts: both spellings, each
73
+ * keeping its existing entries in order and gaining every missing host once.
74
+ */
75
+ export function noProxyEnvWithHosts(env, hosts) {
63
76
  const upper = nonEmpty(env.NO_PROXY);
64
77
  const lower = nonEmpty(env.no_proxy);
65
78
  return {
66
- NO_PROXY: withInferenceBrokerHost(upper ?? lower ?? ''),
67
- no_proxy: withInferenceBrokerHost(lower ?? upper ?? ''),
79
+ NO_PROXY: withNoProxyHosts(upper ?? lower ?? '', hosts),
80
+ no_proxy: withNoProxyHosts(lower ?? upper ?? '', hosts),
68
81
  };
69
82
  }
70
- function withInferenceBrokerHost(list) {
71
- const entries = list.split(',').map((entry) => entry.trim().toLowerCase());
72
- if (entries.includes('*') || entries.includes(INFERENCE_BROKER_HOST))
73
- return list;
74
- const kept = list.replace(WITH_INFERENCE_BROKER_HOST_RE, '');
75
- return kept ? `${kept},${INFERENCE_BROKER_HOST}` : INFERENCE_BROKER_HOST;
83
+ function withNoProxyHosts(list, hosts) {
84
+ let out = list;
85
+ for (const host of hosts) {
86
+ const entries = out.split(',').map((entry) => entry.trim().toLowerCase());
87
+ if (entries.includes('*') || entries.includes(host))
88
+ continue;
89
+ const kept = out.replace(WITH_INFERENCE_BROKER_HOST_RE, '');
90
+ out = kept ? `${kept},${host}` : host;
91
+ }
92
+ return out;
76
93
  }
77
94
  export const MANAGED_SESSION_ENV = 'OVERSKY_MANAGED_SESSION';
78
95
  export const MANAGED_PROMPT_CACHING_ENV = 'OVERSKY_MANAGED_PROMPT_CACHING';
@@ -84,13 +101,62 @@ const ALLOWED_PATHS = new Set([
84
101
  '/v1/responses',
85
102
  '/responses',
86
103
  ]);
87
- const ANTHROPIC_ALLOWED_PATHS = new Set([
88
- '/v1/messages',
89
- '/messages',
90
- '/v1/chat/completions',
91
- '/chat/completions',
104
+ const ANTHROPIC_MESSAGES_PATHS = new Set(['/v1/messages', '/messages']);
105
+ /**
106
+ * Anthropic's token-counting route. Claude Code calls it (`?beta=true`) to size
107
+ * context; the public relay has no route for it, and a count is not something a
108
+ * lease meters. So the broker answers it HERE, as the provider answers a route
109
+ * it does not serve, and Claude Code falls back to its own estimate. Nothing
110
+ * leaves the machine.
111
+ */
112
+ const ANTHROPIC_COUNT_TOKENS_PATHS = new Set([
113
+ '/v1/messages/count_tokens',
114
+ '/messages/count_tokens',
92
115
  ]);
93
- const OPENAI_COMPATIBLE_CHAT_PATHS = new Set(['/v1/chat/completions', '/chat/completions']);
116
+ /**
117
+ * The only query a forwarded request may carry: the Anthropic SDK's beta
118
+ * marker, which Claude Code adds to every Messages call. It selects nothing
119
+ * upstream (the beta features travel in `anthropic-beta`), so it is dropped
120
+ * before forwarding. Any other query is refused rather than ignored, so a
121
+ * route cannot be widened through a parameter the broker never examined.
122
+ */
123
+ const ACCEPTED_ANTHROPIC_QUERY = 'beta=true';
124
+ /** Split an origin-form request target into its path and query. */
125
+ function brokerRequestTarget(target) {
126
+ const queryAt = target.indexOf('?');
127
+ if (queryAt === -1)
128
+ return { path: target, query: '' };
129
+ return { path: target.slice(0, queryAt), query: target.slice(queryAt + 1) };
130
+ }
131
+ /**
132
+ * The path a request may be forwarded under, with its query checked. Throws
133
+ * the broker's ordinary rejection for a query it does not accept.
134
+ */
135
+ function approvedRequestPath(target) {
136
+ if (target.query === '')
137
+ return target.path;
138
+ if (target.query === ACCEPTED_ANTHROPIC_QUERY &&
139
+ (ANTHROPIC_MESSAGES_PATHS.has(target.path) || ANTHROPIC_COUNT_TOKENS_PATHS.has(target.path))) {
140
+ return target.path;
141
+ }
142
+ rejectManagedRequest('managed inference broker denied a request query it does not accept');
143
+ }
144
+ function countTokensUnavailableResponse() {
145
+ const encoded = new TextEncoder().encode(JSON.stringify({
146
+ type: 'error',
147
+ error: {
148
+ type: 'not_found_error',
149
+ message: 'The managed inference broker does not serve token counting; estimate locally.',
150
+ },
151
+ }));
152
+ return {
153
+ status: 404,
154
+ headers: { 'content-type': 'application/json', 'cache-control': 'no-store' },
155
+ body: (async function* () {
156
+ yield encoded;
157
+ })(),
158
+ };
159
+ }
94
160
  const FORWARDED_HEADERS = new Set([
95
161
  'accept',
96
162
  'content-type',
@@ -179,21 +245,16 @@ export function buildManagedInferenceRelayCredential(credential, options) {
179
245
  authToken: sessionToken,
180
246
  };
181
247
  }
182
- /**
183
- * Start the daemon-local, request-envelope-constrained proxy.
184
- *
185
- * skrr Code is a multi-provider ACP runtime, so the child receives each dialect
186
- * it may select: OpenAI/OpenRouter and Anthropic. Every credential variable
187
- * contains the same daemon-local relay secret, never the LiteLLM virtual key.
188
- * The first-party engine must use one of these supplied base URLs for managed
189
- * execution; a failure to do so becomes an auth failure rather than a
190
- * direct-provider fallback.
191
- */
192
248
  export async function startManagedInferenceBroker(options) {
249
+ const transport = options.transport ?? 'unix-socket';
250
+ if (transport !== 'unix-socket' && transport !== 'loopback-tcp') {
251
+ throw new Error('managed inference broker received an unknown transport');
252
+ }
193
253
  const gatewayBase = nonEmpty(options.credential.baseUrl);
194
254
  const gatewayKey = nonEmpty(options.credential.authToken);
195
255
  const modelScope = isManagedInferenceModelScope(options.modelScope) ? options.modelScope : null;
196
256
  const legacyModel = nonEmpty(options.model);
257
+ const promptCacheControl = options.promptCacheControl === 'strip' ? 'strip' : 'refuse';
197
258
  if (!gatewayBase || !gatewayKey || (!modelScope && !legacyModel)) {
198
259
  throw new Error('managed inference broker requires gateway base URL, virtual key, and resolved model');
199
260
  }
@@ -326,10 +387,14 @@ export async function startManagedInferenceBroker(options) {
326
387
  if (request.path === MANAGED_STATUS_PATH) {
327
388
  return statusResponse();
328
389
  }
390
+ const target = brokerRequestTarget(request.path);
391
+ const path = approvedRequestPath(target);
392
+ if (ANTHROPIC_COUNT_TOKENS_PATHS.has(path))
393
+ return countTokensUnavailableResponse();
329
394
  const releaseSlot = acquireRequestSlot();
330
- const url = resolveGatewayUrl(gatewayBase, origin, request.path);
395
+ const url = resolveGatewayUrl(gatewayBase, origin, path);
331
396
  try {
332
- const body = assertApprovedEnvelope(request.method, request.path, request.body, modelScope, legacyModel);
397
+ const body = assertApprovedEnvelope(request.method, path, request.body, modelScope, legacyModel, promptCacheControl);
333
398
  const headers = new Headers();
334
399
  for (const [name, value] of Object.entries(request.headers)) {
335
400
  if (FORWARDED_HEADERS.has(name.toLowerCase()))
@@ -365,34 +430,51 @@ export async function startManagedInferenceBroker(options) {
365
430
  }
366
431
  },
367
432
  };
368
- if (process.platform === 'win32') {
369
- throw new Error('managed inference broker requires a verified local IPC transport on Windows');
370
- }
371
- // Keep below Unix-domain socket path limits even on macOS where os.tmpdir()
372
- // can be deeply nested. The random mkdtemp directory is private to this
373
- // daemon process; the socket itself is chmod 0600 by the listener.
374
- const socketDirectory = mkdtempSync('/tmp/oversky-inference-');
375
- const sharedSocketGroup = Number.isSafeInteger(options.socketGroupId);
376
- if (sharedSocketGroup) {
377
- chownSync(socketDirectory, typeof process.getuid === 'function' ? process.getuid() : -1, options.socketGroupId);
378
- }
379
- chmodSync(socketDirectory, sharedSocketGroup ? 0o750 : 0o700);
380
- const socketPath = join(socketDirectory, 'broker.sock');
381
- const server = new ModelProxyLoopbackServer({
382
- relayToken,
383
- forwarder,
384
- socketPath,
385
- ...(sharedSocketGroup ? { socketGroupId: options.socketGroupId } : {}),
386
- advertisedBaseUrl: INFERENCE_BROKER_ORIGIN,
387
- ...(envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}),
388
- });
389
- try {
390
- await server.start();
391
- }
392
- catch (error) {
393
- rmSync(socketDirectory, { recursive: true, force: true });
394
- throw error;
395
- }
433
+ // The TCP transport has no file-mode fence, so the 256-bit relay token is the
434
+ // whole of its authentication. That is the same token the socket transport
435
+ // checks; the socket's 0600 mode is defence in depth this transport lacks.
436
+ const startListener = async () => {
437
+ if (transport === 'loopback-tcp') {
438
+ const tcp = new ModelProxyLoopbackServer({
439
+ relayToken,
440
+ forwarder,
441
+ host: '127.0.0.1',
442
+ port: 0,
443
+ ...(envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}),
444
+ });
445
+ return { kind: 'tcp', server: tcp, origin: (await tcp.start()).baseUrl };
446
+ }
447
+ if (process.platform === 'win32') {
448
+ throw new Error('managed inference broker requires a verified local IPC transport on Windows');
449
+ }
450
+ // Keep below Unix-domain socket path limits even on macOS where os.tmpdir()
451
+ // can be deeply nested. The random mkdtemp directory is private to this
452
+ // daemon process; the socket itself is chmod 0600 by the listener.
453
+ const directory = mkdtempSync('/tmp/oversky-inference-');
454
+ const sharedSocketGroup = Number.isSafeInteger(options.socketGroupId);
455
+ if (sharedSocketGroup) {
456
+ chownSync(directory, typeof process.getuid === 'function' ? process.getuid() : -1, options.socketGroupId);
457
+ }
458
+ chmodSync(directory, sharedSocketGroup ? 0o750 : 0o700);
459
+ const path = join(directory, 'broker.sock');
460
+ const socket = new ModelProxyLoopbackServer({
461
+ relayToken,
462
+ forwarder,
463
+ socketPath: path,
464
+ ...(sharedSocketGroup ? { socketGroupId: options.socketGroupId } : {}),
465
+ advertisedBaseUrl: INFERENCE_BROKER_ORIGIN,
466
+ ...(envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}),
467
+ });
468
+ try {
469
+ await socket.start();
470
+ }
471
+ catch (error) {
472
+ rmSync(directory, { recursive: true, force: true });
473
+ throw error;
474
+ }
475
+ return { kind: 'socket', server: socket, directory, path };
476
+ };
477
+ const listener = await startListener();
396
478
  let stopped = false;
397
479
  // OSK-3901 — arm the renewal heartbeat once the socket is live.
398
480
  //
@@ -489,6 +571,60 @@ export async function startManagedInferenceBroker(options) {
489
571
  },
490
572
  });
491
573
  }
574
+ const promptCachingEnv = modelScope?.requestEnvelope.allowPromptCaching && supportsManagedPromptCaching(modelScope)
575
+ ? { [MANAGED_PROMPT_CACHING_ENV]: '1' }
576
+ : {};
577
+ const leaseFields = {
578
+ ...(modelScope ? { clientModelId: managedClientModelId(modelScope) } : {}),
579
+ ...(envelope
580
+ ? {
581
+ reasoningPolicy: {
582
+ allowedEfforts: [...envelope.allowedReasoningEfforts],
583
+ defaultEffort: envelope.defaultReasoningEffort ?? envelope.allowedReasoningEfforts[0],
584
+ ...(envelope.selectedReasoningEffort
585
+ ? { requestedEffort: envelope.selectedReasoningEffort }
586
+ : {}),
587
+ ...(envelope.reasoningSelectionSource
588
+ ? { selectionSource: envelope.reasoningSelectionSource }
589
+ : {}),
590
+ },
591
+ }
592
+ : {}),
593
+ };
594
+ const stop = async () => {
595
+ if (stopped)
596
+ return;
597
+ stopped = true;
598
+ // Before the socket: a renewal in flight against a session that is ending
599
+ // would extend a lease nobody will use, and its timer would otherwise keep
600
+ // firing against a dead broker.
601
+ renewal?.stop();
602
+ await listener.server.stop();
603
+ if (listener.kind === 'socket')
604
+ rmSync(listener.directory, { recursive: true, force: true });
605
+ // Drop our own references promptly. JS cannot promise physical memory
606
+ // zeroization, but no subsequent request can authenticate upstream.
607
+ relayToken = '';
608
+ upstreamKey = '';
609
+ };
610
+ if (listener.kind === 'tcp') {
611
+ return {
612
+ // No bearer and no base URL in the environment: a TCP harness is given the
613
+ // endpoint through its SDK, so nothing it starts inherits the token.
614
+ env: { [MANAGED_SESSION_ENV]: '1', ...promptCachingEnv },
615
+ endpoint: {
616
+ origin: listener.origin,
617
+ upstreamProvider: modelScope?.upstreamProvider ?? null,
618
+ bearerToken: () => {
619
+ if (stopped || !relayToken)
620
+ throw new Error('managed inference broker is stopped');
621
+ return relayToken;
622
+ },
623
+ },
624
+ ...leaseFields,
625
+ stop,
626
+ };
627
+ }
492
628
  return {
493
629
  env: {
494
630
  OPENAI_BASE_URL: INFERENCE_BROKER_ORIGIN,
@@ -507,43 +643,13 @@ export async function startManagedInferenceBroker(options) {
507
643
  // Bearer capability that ModelProxyLoopbackServer validates.
508
644
  ANTHROPIC_BASE_URL: INFERENCE_BROKER_ORIGIN,
509
645
  ANTHROPIC_AUTH_TOKEN: relayToken,
510
- [INFERENCE_BROKER_SOCKET_ENV]: socketPath,
646
+ [INFERENCE_BROKER_SOCKET_ENV]: listener.path,
511
647
  [MANAGED_SESSION_ENV]: '1',
512
- ...(modelScope?.requestEnvelope.allowPromptCaching && supportsManagedPromptCaching(modelScope)
513
- ? { [MANAGED_PROMPT_CACHING_ENV]: '1' }
514
- : {}),
515
- },
516
- socketPath,
517
- ...(modelScope ? { clientModelId: managedClientModelId(modelScope) } : {}),
518
- ...(envelope
519
- ? {
520
- reasoningPolicy: {
521
- allowedEfforts: [...envelope.allowedReasoningEfforts],
522
- defaultEffort: envelope.defaultReasoningEffort ?? envelope.allowedReasoningEfforts[0],
523
- ...(envelope.selectedReasoningEffort
524
- ? { requestedEffort: envelope.selectedReasoningEffort }
525
- : {}),
526
- ...(envelope.reasoningSelectionSource
527
- ? { selectionSource: envelope.reasoningSelectionSource }
528
- : {}),
529
- },
530
- }
531
- : {}),
532
- async stop() {
533
- if (stopped)
534
- return;
535
- stopped = true;
536
- // Before the socket: a renewal in flight against a session that is ending
537
- // would extend a lease nobody will use, and its timer would otherwise keep
538
- // firing against a dead broker.
539
- renewal?.stop();
540
- await server.stop();
541
- rmSync(socketDirectory, { recursive: true, force: true });
542
- // Drop our own references promptly. JS cannot promise physical memory
543
- // zeroization, but no subsequent request can authenticate upstream.
544
- relayToken = '';
545
- upstreamKey = '';
648
+ ...promptCachingEnv,
546
649
  },
650
+ socketPath: listener.path,
651
+ ...leaseFields,
652
+ stop,
547
653
  };
548
654
  }
549
655
  /**
@@ -677,7 +783,7 @@ function resolveGatewayUrl(base, allowedOrigin, path) {
677
783
  }
678
784
  return url;
679
785
  }
680
- function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
786
+ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel, promptCacheControl = 'refuse') {
681
787
  if (method.toUpperCase() !== 'POST' || !ALLOWED_PATHS.has(path)) {
682
788
  rejectManagedRequest('managed inference broker denied an unapproved request method or route');
683
789
  }
@@ -703,14 +809,16 @@ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
703
809
  }
704
810
  const requestedModel = payload.model;
705
811
  if (modelScope) {
706
- // The currently published binary may use compatible chat while the target
707
- // binary uses native Messages. Neither dialect authorizes Responses.
708
- if ((modelScope.upstreamProvider === 'anthropic' && !ANTHROPIC_ALLOWED_PATHS.has(path)) ||
709
- (modelScope.upstreamProvider === 'bedrock' && !OPENAI_COMPATIBLE_CHAT_PATHS.has(path)) ||
710
- (!['anthropic', 'bedrock'].includes(modelScope.upstreamProvider) &&
711
- path.endsWith('/messages'))) {
712
- rejectManagedRequest('managed inference broker denied a route outside the provider dialect');
713
- }
812
+ // WHICH dialect may reach this model is not decided here (OSK-24536). Every
813
+ // approved endpoint (`ALLOWED_PATHS`) is forwarded to the authenticated
814
+ // relay, which asks the one cross-protocol route decision with the
815
+ // reservation's harness, attested version and model, and refuses a
816
+ // translation that is not admitted with a typed 403 the broker passes back
817
+ // unchanged. A copy of the rule here could only disagree with it: the copy
818
+ // this replaced refused every translated route, admitted or not, before the
819
+ // relay could judge it. Every host that hands the broker a model scope
820
+ // (the daemon's routes, the CLI) builds the relay credential, so a scoped
821
+ // request has no path to the gateway that skips that decision.
714
822
  // ACP selectors are provider-qualified (`openrouter/anthropic/...` and
715
823
  // `amazon-bedrock/us.anthropic...`), while OpenAI-compatible adapters send
716
824
  // the exact provider-local suffix in the JSON body. Accept that one
@@ -729,7 +837,7 @@ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
729
837
  // the trusted daemon and guarantee the upstream always sees the alias the
730
838
  // key was actually minted for.
731
839
  payload.model = modelScope.wireModel;
732
- enforceRequestEnvelope(payload, path, modelScope.requestEnvelope, modelScope);
840
+ enforceRequestEnvelope(payload, path, modelScope.requestEnvelope, modelScope, promptCacheControl);
733
841
  const sanitized = new TextEncoder().encode(JSON.stringify(payload));
734
842
  if (sanitized.byteLength > modelScope.requestEnvelope.maxInputBytes) {
735
843
  rejectManagedRequest('managed inference broker input byte envelope exceeded');
@@ -741,7 +849,7 @@ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
741
849
  }
742
850
  return body;
743
851
  }
744
- function enforceRequestEnvelope(payload, path, envelope, modelScope) {
852
+ function enforceRequestEnvelope(payload, path, envelope, modelScope, promptCacheControl = 'refuse') {
745
853
  // LiteLLM merges `extra_body` after provider transformation. The child must
746
854
  // never use it to override model, spend, output, or cache fields already
747
855
  // checked by this broker and the authenticated API.
@@ -896,7 +1004,7 @@ function enforceRequestEnvelope(payload, path, envelope, modelScope) {
896
1004
  }
897
1005
  payload.max_reasoning_tokens = Math.min(value, envelope.maxReasoningTokens);
898
1006
  }
899
- enforcePromptCacheEnvelope(payload, envelope, modelScope);
1007
+ enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheControl);
900
1008
  }
901
1009
  function rejectManagedRequest(message) {
902
1010
  throw new ModelProxyError(MODEL_PROXY_ERROR.REQUEST_REJECTED, message);
@@ -910,6 +1018,20 @@ function containsObjectKey(value, target) {
910
1018
  return (Object.prototype.hasOwnProperty.call(record, target) ||
911
1019
  Object.values(record).some((item) => containsObjectKey(item, target)));
912
1020
  }
1021
+ /** Remove every own `target` key, at any depth. Mutates `value`. */
1022
+ function deleteObjectKey(value, target) {
1023
+ if (Array.isArray(value)) {
1024
+ for (const item of value)
1025
+ deleteObjectKey(item, target);
1026
+ return;
1027
+ }
1028
+ if (!value || typeof value !== 'object')
1029
+ return;
1030
+ const record = value;
1031
+ delete record[target];
1032
+ for (const item of Object.values(record))
1033
+ deleteObjectKey(item, target);
1034
+ }
913
1035
  function objectKeyValues(value, target, found = []) {
914
1036
  if (Array.isArray(value)) {
915
1037
  for (const item of value)
@@ -943,7 +1065,7 @@ function supportsManagedPromptCaching(modelScope) {
943
1065
  *
944
1066
  * Source: https://developers.openai.com/api/docs/guides/prompt-caching
945
1067
  */
946
- function enforcePromptCacheEnvelope(payload, envelope, modelScope) {
1068
+ function enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheControl = 'refuse') {
947
1069
  const model = nonEmpty(modelScope.wireModel)
948
1070
  ?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, '')
949
1071
  .toLowerCase();
@@ -953,6 +1075,8 @@ function enforcePromptCacheEnvelope(payload, envelope, modelScope) {
953
1075
  if (envelope.allowPromptCaching) {
954
1076
  rejectManagedRequest('managed inference broker has no prompt cache policy for the leased model');
955
1077
  }
1078
+ if (promptCacheControl === 'strip')
1079
+ deleteObjectKey(payload, 'cache_control');
956
1080
  if (containsObjectKey(payload, 'cache_control') ||
957
1081
  containsObjectKey(payload, 'prompt_cache_breakpoint') ||
958
1082
  payload.prompt_cache_key != null ||
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrr-ai/inference-broker",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "main": "dist/cjs/index.js",
5
5
  "types": "dist/cjs/index.d.ts",
6
6
  "exports": {