@skrr-ai/cli 0.1.171 → 0.1.172

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 +171 -61
  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 +217 -88
  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
@@ -51,7 +51,7 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceInputTokenAccounting, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, type CapabilityRefreshOutcome, type RenewalLoop, type RenewalLoopOptions, type RenewalOutcome, type RenewalStopReason, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer, type ModelProxyForwarder } from './loopback-server.js';
57
57
  export * from './contract.js';
@@ -22,6 +22,7 @@ __export(index_exports, {
22
22
  INFERENCE_BROKER_HOST: () => import_managed_inference_broker.INFERENCE_BROKER_HOST,
23
23
  INFERENCE_BROKER_ORIGIN: () => import_managed_inference_broker.INFERENCE_BROKER_ORIGIN,
24
24
  INFERENCE_BROKER_SOCKET_ENV: () => import_managed_inference_broker.INFERENCE_BROKER_SOCKET_ENV,
25
+ LOOPBACK_BROKER_NO_PROXY_HOSTS: () => import_managed_inference_broker.LOOPBACK_BROKER_NO_PROXY_HOSTS,
25
26
  MANAGED_PROMPT_CACHING_ENV: () => import_managed_inference_broker.MANAGED_PROMPT_CACHING_ENV,
26
27
  MANAGED_SESSION_ENV: () => import_managed_inference_broker.MANAGED_SESSION_ENV,
27
28
  MANAGED_STATUS_PATH: () => import_managed_inference_broker.MANAGED_STATUS_PATH,
@@ -30,6 +31,7 @@ __export(index_exports, {
30
31
  inferenceBrokerNoProxyEnv: () => import_managed_inference_broker.inferenceBrokerNoProxyEnv,
31
32
  isManagedInferenceModelScope: () => import_managed_inference_broker.isManagedInferenceModelScope,
32
33
  minimumCapabilityWindowMs: () => import_managed_inference_renewal.minimumCapabilityWindowMs,
34
+ noProxyEnvWithHosts: () => import_managed_inference_broker.noProxyEnvWithHosts,
33
35
  scheduleRenewalDelay: () => import_managed_inference_renewal.scheduleRenewalDelay,
34
36
  startManagedInferenceBroker: () => import_managed_inference_broker.startManagedInferenceBroker,
35
37
  startRenewalLoop: () => import_managed_inference_renewal.startRenewalLoop
@@ -44,6 +46,7 @@ __reExport(index_exports, require("./contract.js"), module.exports);
44
46
  INFERENCE_BROKER_HOST,
45
47
  INFERENCE_BROKER_ORIGIN,
46
48
  INFERENCE_BROKER_SOCKET_ENV,
49
+ LOOPBACK_BROKER_NO_PROXY_HOSTS,
47
50
  MANAGED_PROMPT_CACHING_ENV,
48
51
  MANAGED_SESSION_ENV,
49
52
  MANAGED_STATUS_PATH,
@@ -52,6 +55,7 @@ __reExport(index_exports, require("./contract.js"), module.exports);
52
55
  inferenceBrokerNoProxyEnv,
53
56
  isManagedInferenceModelScope,
54
57
  minimumCapabilityWindowMs,
58
+ noProxyEnvWithHosts,
55
59
  scheduleRenewalDelay,
56
60
  startManagedInferenceBroker,
57
61
  startRenewalLoop,
@@ -117,6 +117,40 @@ export interface ManagedInferenceBrokerOptions {
117
117
  fetchImpl?: FetchLike;
118
118
  /** Trusted cross-uid group for a Dedicated Runtime harness child. */
119
119
  socketGroupId?: number;
120
+ /**
121
+ * How the harness reaches the broker. `unix-socket` (the default) is a 0600
122
+ * socket the harness addresses through {@link INFERENCE_BROKER_SOCKET_ENV}.
123
+ * `loopback-tcp` is a 127.0.0.1 ephemeral port for a closed runtime that can
124
+ * only speak HTTP over TCP (the GitHub Copilot runtime); the bearer is then
125
+ * handed out only through {@link ManagedInferenceEndpoint.bearerToken} and is
126
+ * never written into `env`.
127
+ */
128
+ transport?: ManagedInferenceBrokerTransport;
129
+ /**
130
+ * What a managed lease that does NOT allow prompt caching does with an
131
+ * Anthropic-dialect `cache_control` marker. `refuse` (the default) fails the
132
+ * request. `strip` removes the markers and forwards the request uncached,
133
+ * for a harness that always sends them and cannot be told not to (Claude
134
+ * Code, OSK-24457). Stripping can only lower what a request costs: a cache
135
+ * write is billed above an ordinary input token, an uncached read is not.
136
+ * Every other prompt-cache field is still refused, and a lease that ALLOWS
137
+ * caching for a Claude-family model is still refused (there is no policy for
138
+ * it yet), whichever value is set.
139
+ */
140
+ promptCacheControl?: 'refuse' | 'strip';
141
+ }
142
+ export type ManagedInferenceBrokerTransport = 'unix-socket' | 'loopback-tcp';
143
+ /**
144
+ * A `loopback-tcp` broker's address. The bearer is a function rather than a
145
+ * value so it can be read per request (an SDK `bearerTokenProvider`) and stops
146
+ * authenticating anything once `stop()` has run.
147
+ */
148
+ export interface ManagedInferenceEndpoint {
149
+ /** `http://127.0.0.1:<port>`, no path. */
150
+ readonly origin: string;
151
+ /** The lease's upstream dialect family, so a caller can pick the client wire. */
152
+ readonly upstreamProvider: ManagedInferenceModelScope['upstreamProvider'] | null;
153
+ bearerToken(): string;
120
154
  }
121
155
  export interface ManagedInferenceBrokerSession {
122
156
  /** Safe-to-deliver child environment. It intentionally never includes the gateway key. */
@@ -133,6 +167,10 @@ export interface ManagedInferenceBrokerSession {
133
167
  reasoningPolicy?: ManagedReasoningPolicy;
134
168
  stop(): Promise<void>;
135
169
  }
170
+ /** A `loopback-tcp` broker: no socket, and no bearer in `env`. */
171
+ export interface ManagedInferenceLoopbackSession extends Omit<ManagedInferenceBrokerSession, 'socketPath'> {
172
+ endpoint: ManagedInferenceEndpoint;
173
+ }
136
174
  /**
137
175
  * OSK-3893 — reserved local path the engine reads for its managed-session readout.
138
176
  *
@@ -210,6 +248,20 @@ export declare function inferenceBrokerNoProxyEnv(env: Readonly<Record<string, s
210
248
  NO_PROXY: string;
211
249
  no_proxy: string;
212
250
  };
251
+ /**
252
+ * The loopback hosts a `loopback-tcp` broker is reached on. A harness that
253
+ * honours HTTP(S)_PROXY would otherwise send its model traffic, relay token
254
+ * included, to the proxy instead of to this machine (OSK-24457).
255
+ */
256
+ export declare const LOOPBACK_BROKER_NO_PROXY_HOSTS: readonly string[];
257
+ /**
258
+ * {@link inferenceBrokerNoProxyEnv} for any set of hosts: both spellings, each
259
+ * keeping its existing entries in order and gaining every missing host once.
260
+ */
261
+ export declare function noProxyEnvWithHosts(env: Readonly<Record<string, string | undefined>>, hosts: readonly string[]): {
262
+ NO_PROXY: string;
263
+ no_proxy: string;
264
+ };
213
265
  export declare const MANAGED_SESSION_ENV = "OVERSKY_MANAGED_SESSION";
214
266
  export declare const MANAGED_PROMPT_CACHING_ENV = "OVERSKY_MANAGED_PROMPT_CACHING";
215
267
  export declare function managedClientModelId(scope: ManagedInferenceModelScope): string;
@@ -238,7 +290,12 @@ export declare function buildManagedInferenceRelayCredential(credential: Gateway
238
290
  * execution; a failure to do so becomes an auth failure rather than a
239
291
  * direct-provider fallback.
240
292
  */
241
- export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions): Promise<ManagedInferenceBrokerSession>;
293
+ export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions & {
294
+ transport: 'loopback-tcp';
295
+ }): Promise<ManagedInferenceLoopbackSession>;
296
+ export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions & {
297
+ transport?: 'unix-socket';
298
+ }): Promise<ManagedInferenceBrokerSession>;
242
299
  /**
243
300
  * Classify a NON-OK lease renewal response.
244
301
  *
@@ -21,6 +21,7 @@ __export(managed_inference_broker_exports, {
21
21
  INFERENCE_BROKER_HOST: () => INFERENCE_BROKER_HOST,
22
22
  INFERENCE_BROKER_ORIGIN: () => INFERENCE_BROKER_ORIGIN,
23
23
  INFERENCE_BROKER_SOCKET_ENV: () => INFERENCE_BROKER_SOCKET_ENV,
24
+ LOOPBACK_BROKER_NO_PROXY_HOSTS: () => LOOPBACK_BROKER_NO_PROXY_HOSTS,
24
25
  MANAGED_PROMPT_CACHING_ENV: () => MANAGED_PROMPT_CACHING_ENV,
25
26
  MANAGED_SESSION_ENV: () => MANAGED_SESSION_ENV,
26
27
  MANAGED_STATUS_PATH: () => MANAGED_STATUS_PATH,
@@ -30,6 +31,7 @@ __export(managed_inference_broker_exports, {
30
31
  isGatewayCredential: () => isGatewayCredential,
31
32
  isManagedInferenceModelScope: () => isManagedInferenceModelScope,
32
33
  managedClientModelId: () => managedClientModelId,
34
+ noProxyEnvWithHosts: () => noProxyEnvWithHosts,
33
35
  startManagedInferenceBroker: () => startManagedInferenceBroker
34
36
  });
35
37
  module.exports = __toCommonJS(managed_inference_broker_exports);
@@ -48,19 +50,27 @@ const INFERENCE_BROKER_ORIGIN = "http://oversky-inference-broker.invalid";
48
50
  const INFERENCE_BROKER_HOST = new URL(INFERENCE_BROKER_ORIGIN).hostname;
49
51
  const INFERENCE_BROKER_SOCKET_ENV = "OVERSKY_INFERENCE_BROKER_SOCKET";
50
52
  function inferenceBrokerNoProxyEnv(env) {
53
+ return noProxyEnvWithHosts(env, [INFERENCE_BROKER_HOST]);
54
+ }
55
+ const LOOPBACK_BROKER_NO_PROXY_HOSTS = ["127.0.0.1", "localhost"];
56
+ function noProxyEnvWithHosts(env, hosts) {
51
57
  const upper = nonEmpty(env.NO_PROXY);
52
58
  const lower = nonEmpty(env.no_proxy);
53
59
  return {
54
- NO_PROXY: withInferenceBrokerHost(upper ?? lower ?? ""),
55
- no_proxy: withInferenceBrokerHost(lower ?? upper ?? "")
60
+ NO_PROXY: withNoProxyHosts(upper ?? lower ?? "", hosts),
61
+ no_proxy: withNoProxyHosts(lower ?? upper ?? "", hosts)
56
62
  };
57
63
  }
58
- function withInferenceBrokerHost(list) {
59
- const entries = list.split(",").map((entry) => entry.trim().toLowerCase());
60
- if (entries.includes("*") || entries.includes(INFERENCE_BROKER_HOST))
61
- return list;
62
- const kept = list.replace(WITH_INFERENCE_BROKER_HOST_RE, "");
63
- return kept ? `${kept},${INFERENCE_BROKER_HOST}` : INFERENCE_BROKER_HOST;
64
+ function withNoProxyHosts(list, hosts) {
65
+ let out = list;
66
+ for (const host of hosts) {
67
+ const entries = out.split(",").map((entry) => entry.trim().toLowerCase());
68
+ if (entries.includes("*") || entries.includes(host))
69
+ continue;
70
+ const kept = out.replace(WITH_INFERENCE_BROKER_HOST_RE, "");
71
+ out = kept ? `${kept},${host}` : host;
72
+ }
73
+ return out;
64
74
  }
65
75
  const MANAGED_SESSION_ENV = "OVERSKY_MANAGED_SESSION";
66
76
  const MANAGED_PROMPT_CACHING_ENV = "OVERSKY_MANAGED_PROMPT_CACHING";
@@ -79,6 +89,42 @@ const ANTHROPIC_ALLOWED_PATHS = /* @__PURE__ */ new Set([
79
89
  "/chat/completions"
80
90
  ]);
81
91
  const OPENAI_COMPATIBLE_CHAT_PATHS = /* @__PURE__ */ new Set(["/v1/chat/completions", "/chat/completions"]);
92
+ const ANTHROPIC_MESSAGES_PATHS = /* @__PURE__ */ new Set(["/v1/messages", "/messages"]);
93
+ const ANTHROPIC_COUNT_TOKENS_PATHS = /* @__PURE__ */ new Set([
94
+ "/v1/messages/count_tokens",
95
+ "/messages/count_tokens"
96
+ ]);
97
+ const ACCEPTED_ANTHROPIC_QUERY = "beta=true";
98
+ function brokerRequestTarget(target) {
99
+ const queryAt = target.indexOf("?");
100
+ if (queryAt === -1)
101
+ return { path: target, query: "" };
102
+ return { path: target.slice(0, queryAt), query: target.slice(queryAt + 1) };
103
+ }
104
+ function approvedRequestPath(target) {
105
+ if (target.query === "")
106
+ return target.path;
107
+ if (target.query === ACCEPTED_ANTHROPIC_QUERY && (ANTHROPIC_MESSAGES_PATHS.has(target.path) || ANTHROPIC_COUNT_TOKENS_PATHS.has(target.path))) {
108
+ return target.path;
109
+ }
110
+ rejectManagedRequest("managed inference broker denied a request query it does not accept");
111
+ }
112
+ function countTokensUnavailableResponse() {
113
+ const encoded = new TextEncoder().encode(JSON.stringify({
114
+ type: "error",
115
+ error: {
116
+ type: "not_found_error",
117
+ message: "The managed inference broker does not serve token counting; estimate locally."
118
+ }
119
+ }));
120
+ return {
121
+ status: 404,
122
+ headers: { "content-type": "application/json", "cache-control": "no-store" },
123
+ body: (async function* () {
124
+ yield encoded;
125
+ })()
126
+ };
127
+ }
82
128
  const FORWARDED_HEADERS = /* @__PURE__ */ new Set([
83
129
  "accept",
84
130
  "content-type",
@@ -140,10 +186,15 @@ function buildManagedInferenceRelayCredential(credential, options) {
140
186
  };
141
187
  }
142
188
  async function startManagedInferenceBroker(options) {
189
+ const transport = options.transport ?? "unix-socket";
190
+ if (transport !== "unix-socket" && transport !== "loopback-tcp") {
191
+ throw new Error("managed inference broker received an unknown transport");
192
+ }
143
193
  const gatewayBase = nonEmpty(options.credential.baseUrl);
144
194
  const gatewayKey = nonEmpty(options.credential.authToken);
145
195
  const modelScope = isManagedInferenceModelScope(options.modelScope) ? options.modelScope : null;
146
196
  const legacyModel = nonEmpty(options.model);
197
+ const promptCacheControl = options.promptCacheControl === "strip" ? "strip" : "refuse";
147
198
  if (!gatewayBase || !gatewayKey || !modelScope && !legacyModel) {
148
199
  throw new Error("managed inference broker requires gateway base URL, virtual key, and resolved model");
149
200
  }
@@ -231,10 +282,14 @@ async function startManagedInferenceBroker(options) {
231
282
  if (request.path === MANAGED_STATUS_PATH) {
232
283
  return statusResponse();
233
284
  }
285
+ const target = brokerRequestTarget(request.path);
286
+ const path = approvedRequestPath(target);
287
+ if (ANTHROPIC_COUNT_TOKENS_PATHS.has(path))
288
+ return countTokensUnavailableResponse();
234
289
  const releaseSlot = acquireRequestSlot();
235
- const url = resolveGatewayUrl(gatewayBase, origin, request.path);
290
+ const url = resolveGatewayUrl(gatewayBase, origin, path);
236
291
  try {
237
- const body = assertApprovedEnvelope(request.method, request.path, request.body, modelScope, legacyModel);
292
+ const body = assertApprovedEnvelope(request.method, path, request.body, modelScope, legacyModel, promptCacheControl);
238
293
  const headers = new Headers();
239
294
  for (const [name, value] of Object.entries(request.headers)) {
240
295
  if (FORWARDED_HEADERS.has(name.toLowerCase()))
@@ -261,30 +316,44 @@ async function startManagedInferenceBroker(options) {
261
316
  }
262
317
  }
263
318
  };
264
- if (process.platform === "win32") {
265
- throw new Error("managed inference broker requires a verified local IPC transport on Windows");
266
- }
267
- const socketDirectory = (0, import_node_fs.mkdtempSync)("/tmp/oversky-inference-");
268
- const sharedSocketGroup = Number.isSafeInteger(options.socketGroupId);
269
- if (sharedSocketGroup) {
270
- (0, import_node_fs.chownSync)(socketDirectory, typeof process.getuid === "function" ? process.getuid() : -1, options.socketGroupId);
271
- }
272
- (0, import_node_fs.chmodSync)(socketDirectory, sharedSocketGroup ? 488 : 448);
273
- const socketPath = (0, import_node_path.join)(socketDirectory, "broker.sock");
274
- const server = new import_loopback_server.ModelProxyLoopbackServer({
275
- relayToken,
276
- forwarder,
277
- socketPath,
278
- ...sharedSocketGroup ? { socketGroupId: options.socketGroupId } : {},
279
- advertisedBaseUrl: INFERENCE_BROKER_ORIGIN,
280
- ...envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}
281
- });
282
- try {
283
- await server.start();
284
- } catch (error) {
285
- (0, import_node_fs.rmSync)(socketDirectory, { recursive: true, force: true });
286
- throw error;
287
- }
319
+ const startListener = async () => {
320
+ if (transport === "loopback-tcp") {
321
+ const tcp = new import_loopback_server.ModelProxyLoopbackServer({
322
+ relayToken,
323
+ forwarder,
324
+ host: "127.0.0.1",
325
+ port: 0,
326
+ ...envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}
327
+ });
328
+ return { kind: "tcp", server: tcp, origin: (await tcp.start()).baseUrl };
329
+ }
330
+ if (process.platform === "win32") {
331
+ throw new Error("managed inference broker requires a verified local IPC transport on Windows");
332
+ }
333
+ const directory = (0, import_node_fs.mkdtempSync)("/tmp/oversky-inference-");
334
+ const sharedSocketGroup = Number.isSafeInteger(options.socketGroupId);
335
+ if (sharedSocketGroup) {
336
+ (0, import_node_fs.chownSync)(directory, typeof process.getuid === "function" ? process.getuid() : -1, options.socketGroupId);
337
+ }
338
+ (0, import_node_fs.chmodSync)(directory, sharedSocketGroup ? 488 : 448);
339
+ const path = (0, import_node_path.join)(directory, "broker.sock");
340
+ const socket = new import_loopback_server.ModelProxyLoopbackServer({
341
+ relayToken,
342
+ forwarder,
343
+ socketPath: path,
344
+ ...sharedSocketGroup ? { socketGroupId: options.socketGroupId } : {},
345
+ advertisedBaseUrl: INFERENCE_BROKER_ORIGIN,
346
+ ...envelope ? { maxBodyBytes: envelope.maxInputBytes } : {}
347
+ });
348
+ try {
349
+ await socket.start();
350
+ } catch (error) {
351
+ (0, import_node_fs.rmSync)(directory, { recursive: true, force: true });
352
+ throw error;
353
+ }
354
+ return { kind: "socket", server: socket, directory, path };
355
+ };
356
+ const listener = await startListener();
288
357
  let stopped = false;
289
358
  if (options.leaseExpiresInMs && options.leaseExpiresInMs > 0) {
290
359
  const renewUrl = `${gatewayBase.replace(START_MANAGED_INFERENCE_BROKER_RE, "")}/renew`;
@@ -341,6 +410,47 @@ async function startManagedInferenceBroker(options) {
341
410
  }
342
411
  });
343
412
  }
413
+ const promptCachingEnv = modelScope?.requestEnvelope.allowPromptCaching && supportsManagedPromptCaching(modelScope) ? { [MANAGED_PROMPT_CACHING_ENV]: "1" } : {};
414
+ const leaseFields = {
415
+ ...modelScope ? { clientModelId: managedClientModelId(modelScope) } : {},
416
+ ...envelope ? {
417
+ reasoningPolicy: {
418
+ allowedEfforts: [...envelope.allowedReasoningEfforts],
419
+ defaultEffort: envelope.defaultReasoningEffort ?? envelope.allowedReasoningEfforts[0],
420
+ ...envelope.selectedReasoningEffort ? { requestedEffort: envelope.selectedReasoningEffort } : {},
421
+ ...envelope.reasoningSelectionSource ? { selectionSource: envelope.reasoningSelectionSource } : {}
422
+ }
423
+ } : {}
424
+ };
425
+ const stop = async () => {
426
+ if (stopped)
427
+ return;
428
+ stopped = true;
429
+ renewal?.stop();
430
+ await listener.server.stop();
431
+ if (listener.kind === "socket")
432
+ (0, import_node_fs.rmSync)(listener.directory, { recursive: true, force: true });
433
+ relayToken = "";
434
+ upstreamKey = "";
435
+ };
436
+ if (listener.kind === "tcp") {
437
+ return {
438
+ // No bearer and no base URL in the environment: a TCP harness is given the
439
+ // endpoint through its SDK, so nothing it starts inherits the token.
440
+ env: { [MANAGED_SESSION_ENV]: "1", ...promptCachingEnv },
441
+ endpoint: {
442
+ origin: listener.origin,
443
+ upstreamProvider: modelScope?.upstreamProvider ?? null,
444
+ bearerToken: () => {
445
+ if (stopped || !relayToken)
446
+ throw new Error("managed inference broker is stopped");
447
+ return relayToken;
448
+ }
449
+ },
450
+ ...leaseFields,
451
+ stop
452
+ };
453
+ }
344
454
  return {
345
455
  env: {
346
456
  OPENAI_BASE_URL: INFERENCE_BROKER_ORIGIN,
@@ -359,30 +469,13 @@ async function startManagedInferenceBroker(options) {
359
469
  // Bearer capability that ModelProxyLoopbackServer validates.
360
470
  ANTHROPIC_BASE_URL: INFERENCE_BROKER_ORIGIN,
361
471
  ANTHROPIC_AUTH_TOKEN: relayToken,
362
- [INFERENCE_BROKER_SOCKET_ENV]: socketPath,
472
+ [INFERENCE_BROKER_SOCKET_ENV]: listener.path,
363
473
  [MANAGED_SESSION_ENV]: "1",
364
- ...modelScope?.requestEnvelope.allowPromptCaching && supportsManagedPromptCaching(modelScope) ? { [MANAGED_PROMPT_CACHING_ENV]: "1" } : {}
474
+ ...promptCachingEnv
365
475
  },
366
- socketPath,
367
- ...modelScope ? { clientModelId: managedClientModelId(modelScope) } : {},
368
- ...envelope ? {
369
- reasoningPolicy: {
370
- allowedEfforts: [...envelope.allowedReasoningEfforts],
371
- defaultEffort: envelope.defaultReasoningEffort ?? envelope.allowedReasoningEfforts[0],
372
- ...envelope.selectedReasoningEffort ? { requestedEffort: envelope.selectedReasoningEffort } : {},
373
- ...envelope.reasoningSelectionSource ? { selectionSource: envelope.reasoningSelectionSource } : {}
374
- }
375
- } : {},
376
- async stop() {
377
- if (stopped)
378
- return;
379
- stopped = true;
380
- renewal?.stop();
381
- await server.stop();
382
- (0, import_node_fs.rmSync)(socketDirectory, { recursive: true, force: true });
383
- relayToken = "";
384
- upstreamKey = "";
385
- }
476
+ socketPath: listener.path,
477
+ ...leaseFields,
478
+ stop
386
479
  };
387
480
  }
388
481
  const LEASE_CEILING_CODE = "lease-ceiling-reached";
@@ -452,7 +545,7 @@ function resolveGatewayUrl(base, allowedOrigin, path) {
452
545
  }
453
546
  return url;
454
547
  }
455
- function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
548
+ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel, promptCacheControl = "refuse") {
456
549
  if (method.toUpperCase() !== "POST" || !ALLOWED_PATHS.has(path)) {
457
550
  rejectManagedRequest("managed inference broker denied an unapproved request method or route");
458
551
  }
@@ -481,7 +574,7 @@ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
481
574
  rejectManagedRequest("managed inference broker denied a model outside the approved lease");
482
575
  }
483
576
  payload.model = modelScope.wireModel;
484
- enforceRequestEnvelope(payload, path, modelScope.requestEnvelope, modelScope);
577
+ enforceRequestEnvelope(payload, path, modelScope.requestEnvelope, modelScope, promptCacheControl);
485
578
  const sanitized = new TextEncoder().encode(JSON.stringify(payload));
486
579
  if (sanitized.byteLength > modelScope.requestEnvelope.maxInputBytes) {
487
580
  rejectManagedRequest("managed inference broker input byte envelope exceeded");
@@ -493,7 +586,7 @@ function assertApprovedEnvelope(method, path, body, modelScope, legacyModel) {
493
586
  }
494
587
  return body;
495
588
  }
496
- function enforceRequestEnvelope(payload, path, envelope, modelScope) {
589
+ function enforceRequestEnvelope(payload, path, envelope, modelScope, promptCacheControl = "refuse") {
497
590
  if (payload.extra_body != null) {
498
591
  rejectManagedRequest("managed inference broker denied a caller-supplied extra body");
499
592
  }
@@ -587,7 +680,7 @@ function enforceRequestEnvelope(payload, path, envelope, modelScope) {
587
680
  }
588
681
  payload.max_reasoning_tokens = Math.min(value, envelope.maxReasoningTokens);
589
682
  }
590
- enforcePromptCacheEnvelope(payload, envelope, modelScope);
683
+ enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheControl);
591
684
  }
592
685
  function rejectManagedRequest(message) {
593
686
  throw new import_contract.ModelProxyError(import_contract.MODEL_PROXY_ERROR.REQUEST_REJECTED, message);
@@ -600,6 +693,19 @@ function containsObjectKey(value, target) {
600
693
  const record = value;
601
694
  return Object.prototype.hasOwnProperty.call(record, target) || Object.values(record).some((item) => containsObjectKey(item, target));
602
695
  }
696
+ function deleteObjectKey(value, target) {
697
+ if (Array.isArray(value)) {
698
+ for (const item of value)
699
+ deleteObjectKey(item, target);
700
+ return;
701
+ }
702
+ if (!value || typeof value !== "object")
703
+ return;
704
+ const record = value;
705
+ delete record[target];
706
+ for (const item of Object.values(record))
707
+ deleteObjectKey(item, target);
708
+ }
603
709
  function objectKeyValues(value, target, found = []) {
604
710
  if (Array.isArray(value)) {
605
711
  for (const item of value)
@@ -623,13 +729,15 @@ function supportsManagedPromptCaching(modelScope) {
623
729
  const model = nonEmpty(modelScope.wireModel)?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, "").toLowerCase();
624
730
  return modelScope.upstreamProvider === "openai" && Boolean(model?.startsWith("gpt-5.6"));
625
731
  }
626
- function enforcePromptCacheEnvelope(payload, envelope, modelScope) {
732
+ function enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheControl = "refuse") {
627
733
  const model = nonEmpty(modelScope.wireModel)?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, "").toLowerCase();
628
734
  const claudeCacheControlFamily = ["anthropic", "openrouter", "bedrock"].includes(modelScope.upstreamProvider) && model?.includes("claude");
629
735
  if (claudeCacheControlFamily) {
630
736
  if (envelope.allowPromptCaching) {
631
737
  rejectManagedRequest("managed inference broker has no prompt cache policy for the leased model");
632
738
  }
739
+ if (promptCacheControl === "strip")
740
+ deleteObjectKey(payload, "cache_control");
633
741
  if (containsObjectKey(payload, "cache_control") || containsObjectKey(payload, "prompt_cache_breakpoint") || payload.prompt_cache_key != null || payload.prompt_cache_options != null || payload.prompt_cache_retention != null) {
634
742
  rejectManagedRequest("managed inference broker denied prompt caching outside the lease envelope");
635
743
  }
@@ -741,6 +849,7 @@ async function* responseBody(response, maxBytes, onComplete = () => {
741
849
  INFERENCE_BROKER_HOST,
742
850
  INFERENCE_BROKER_ORIGIN,
743
851
  INFERENCE_BROKER_SOCKET_ENV,
852
+ LOOPBACK_BROKER_NO_PROXY_HOSTS,
744
853
  MANAGED_PROMPT_CACHING_ENV,
745
854
  MANAGED_SESSION_ENV,
746
855
  MANAGED_STATUS_PATH,
@@ -750,5 +859,6 @@ async function* responseBody(response, maxBytes, onComplete = () => {
750
859
  isGatewayCredential,
751
860
  isManagedInferenceModelScope,
752
861
  managedClientModelId,
862
+ noProxyEnvWithHosts,
753
863
  startManagedInferenceBroker
754
864
  });
@@ -51,7 +51,7 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceInputTokenAccounting, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, type CapabilityRefreshOutcome, type RenewalLoop, type RenewalLoopOptions, type RenewalOutcome, type RenewalStopReason, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer, type ModelProxyForwarder } from './loopback-server.js';
57
57
  export * from './contract.js';
@@ -51,7 +51,7 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer } from './loopback-server.js';
57
57
  // Re-exported in full because `daemon/src/model-proxy/contract.ts` becomes a
@@ -117,6 +117,40 @@ export interface ManagedInferenceBrokerOptions {
117
117
  fetchImpl?: FetchLike;
118
118
  /** Trusted cross-uid group for a Dedicated Runtime harness child. */
119
119
  socketGroupId?: number;
120
+ /**
121
+ * How the harness reaches the broker. `unix-socket` (the default) is a 0600
122
+ * socket the harness addresses through {@link INFERENCE_BROKER_SOCKET_ENV}.
123
+ * `loopback-tcp` is a 127.0.0.1 ephemeral port for a closed runtime that can
124
+ * only speak HTTP over TCP (the GitHub Copilot runtime); the bearer is then
125
+ * handed out only through {@link ManagedInferenceEndpoint.bearerToken} and is
126
+ * never written into `env`.
127
+ */
128
+ transport?: ManagedInferenceBrokerTransport;
129
+ /**
130
+ * What a managed lease that does NOT allow prompt caching does with an
131
+ * Anthropic-dialect `cache_control` marker. `refuse` (the default) fails the
132
+ * request. `strip` removes the markers and forwards the request uncached,
133
+ * for a harness that always sends them and cannot be told not to (Claude
134
+ * Code, OSK-24457). Stripping can only lower what a request costs: a cache
135
+ * write is billed above an ordinary input token, an uncached read is not.
136
+ * Every other prompt-cache field is still refused, and a lease that ALLOWS
137
+ * caching for a Claude-family model is still refused (there is no policy for
138
+ * it yet), whichever value is set.
139
+ */
140
+ promptCacheControl?: 'refuse' | 'strip';
141
+ }
142
+ export type ManagedInferenceBrokerTransport = 'unix-socket' | 'loopback-tcp';
143
+ /**
144
+ * A `loopback-tcp` broker's address. The bearer is a function rather than a
145
+ * value so it can be read per request (an SDK `bearerTokenProvider`) and stops
146
+ * authenticating anything once `stop()` has run.
147
+ */
148
+ export interface ManagedInferenceEndpoint {
149
+ /** `http://127.0.0.1:<port>`, no path. */
150
+ readonly origin: string;
151
+ /** The lease's upstream dialect family, so a caller can pick the client wire. */
152
+ readonly upstreamProvider: ManagedInferenceModelScope['upstreamProvider'] | null;
153
+ bearerToken(): string;
120
154
  }
121
155
  export interface ManagedInferenceBrokerSession {
122
156
  /** Safe-to-deliver child environment. It intentionally never includes the gateway key. */
@@ -133,6 +167,10 @@ export interface ManagedInferenceBrokerSession {
133
167
  reasoningPolicy?: ManagedReasoningPolicy;
134
168
  stop(): Promise<void>;
135
169
  }
170
+ /** A `loopback-tcp` broker: no socket, and no bearer in `env`. */
171
+ export interface ManagedInferenceLoopbackSession extends Omit<ManagedInferenceBrokerSession, 'socketPath'> {
172
+ endpoint: ManagedInferenceEndpoint;
173
+ }
136
174
  /**
137
175
  * OSK-3893 — reserved local path the engine reads for its managed-session readout.
138
176
  *
@@ -210,6 +248,20 @@ export declare function inferenceBrokerNoProxyEnv(env: Readonly<Record<string, s
210
248
  NO_PROXY: string;
211
249
  no_proxy: string;
212
250
  };
251
+ /**
252
+ * The loopback hosts a `loopback-tcp` broker is reached on. A harness that
253
+ * honours HTTP(S)_PROXY would otherwise send its model traffic, relay token
254
+ * included, to the proxy instead of to this machine (OSK-24457).
255
+ */
256
+ export declare const LOOPBACK_BROKER_NO_PROXY_HOSTS: readonly string[];
257
+ /**
258
+ * {@link inferenceBrokerNoProxyEnv} for any set of hosts: both spellings, each
259
+ * keeping its existing entries in order and gaining every missing host once.
260
+ */
261
+ export declare function noProxyEnvWithHosts(env: Readonly<Record<string, string | undefined>>, hosts: readonly string[]): {
262
+ NO_PROXY: string;
263
+ no_proxy: string;
264
+ };
213
265
  export declare const MANAGED_SESSION_ENV = "OVERSKY_MANAGED_SESSION";
214
266
  export declare const MANAGED_PROMPT_CACHING_ENV = "OVERSKY_MANAGED_PROMPT_CACHING";
215
267
  export declare function managedClientModelId(scope: ManagedInferenceModelScope): string;
@@ -238,7 +290,12 @@ export declare function buildManagedInferenceRelayCredential(credential: Gateway
238
290
  * execution; a failure to do so becomes an auth failure rather than a
239
291
  * direct-provider fallback.
240
292
  */
241
- export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions): Promise<ManagedInferenceBrokerSession>;
293
+ export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions & {
294
+ transport: 'loopback-tcp';
295
+ }): Promise<ManagedInferenceLoopbackSession>;
296
+ export declare function startManagedInferenceBroker(options: ManagedInferenceBrokerOptions & {
297
+ transport?: 'unix-socket';
298
+ }): Promise<ManagedInferenceBrokerSession>;
242
299
  /**
243
300
  * Classify a NON-OK lease renewal response.
244
301
  *