@skrr-ai/cli 0.1.175 → 0.1.177
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.
- package/dist/commands/harnesses/leases/show.js +8 -0
- package/dist/commands/harnesses/show.js +3 -0
- package/dist/lib/dedicated-wait.js +2 -0
- package/dist/lib/harness-engine-update.d.ts +5 -0
- package/dist/lib/harness-engine-update.js +82 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.d.ts +7 -8
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarness.js +11 -7
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessUpdater.d.ts +29 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/firstPartyHarnessUpdater.js +57 -6
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.d.ts +25 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.js +20 -6
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.d.ts +7 -8
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarness.js +11 -7
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessUpdater.d.ts +29 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/firstPartyHarnessUpdater.js +71 -4
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.d.ts +25 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.js +31 -5
- package/dist/node_modules/@skrr-ai/data-provider/index.js +8038 -8034
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/contract.d.ts +5 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/contract.js +6 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.d.ts +1 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.js +8 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/loopback-server.d.ts +4 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/loopback-server.js +4 -2
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.d.ts +96 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.js +108 -9
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/contract.d.ts +5 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/contract.js +5 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.d.ts +1 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.js +1 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/loopback-server.d.ts +4 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/loopback-server.js +1 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.d.ts +96 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.js +149 -11
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* endpoint, and the child receives only a random secret usable against that
|
|
10
10
|
* endpoint while it is alive.
|
|
11
11
|
*/
|
|
12
|
+
import { MODEL_PROXY_ERROR } from './contract.js';
|
|
12
13
|
import { type CapabilityRefreshOutcome, type RenewalOutcome, type RenewalStopReason } from './managed-inference-renewal.js';
|
|
13
14
|
type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
14
15
|
export interface GatewayCredential {
|
|
@@ -82,8 +83,51 @@ export type ManagedCapabilityRefreshResult = CapabilityRefreshOutcome & {
|
|
|
82
83
|
token?: string;
|
|
83
84
|
};
|
|
84
85
|
export type ManagedCapabilityRefresh = () => Promise<ManagedCapabilityRefreshResult>;
|
|
86
|
+
/**
|
|
87
|
+
* OSK-24521 — an upstream that authenticates each request itself.
|
|
88
|
+
*
|
|
89
|
+
* The broker's other credential source is a capability it holds (`credential.authToken`) and sends
|
|
90
|
+
* as `Authorization: Bearer`. A host whose credential renews on its own clock (the API worker's
|
|
91
|
+
* process `agent.turn` key, which lives 900 s and is replaced ahead of expiry) cannot hand the
|
|
92
|
+
* broker one value for a session that outlives it, so it hands over the sending instead: `send`
|
|
93
|
+
* puts the key that is current at that moment on the request (and may send it once more on a
|
|
94
|
+
* replacement when the gateway refused the key, with the same buffered body). The broker then sets
|
|
95
|
+
* no authorization of its own and never sees a key.
|
|
96
|
+
*
|
|
97
|
+
* `send` refuses BEFORE the network when it has no key to send, by throwing a
|
|
98
|
+
* {@link ModelProxyError} with {@link MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE}. The broker answers
|
|
99
|
+
* that request itself (see {@link CREDENTIAL_UNAVAILABLE_STATUS}), sends nothing upstream, and keeps
|
|
100
|
+
* the refusal for its host ({@link ManagedInferenceBrokerSession.localRefusal}). Any other throw is
|
|
101
|
+
* the upstream failing, as for the capability source.
|
|
102
|
+
*/
|
|
103
|
+
export interface ManagedInferenceUpstreamTransport {
|
|
104
|
+
send(url: string, init: RequestInit): Promise<Response>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A request the broker answered itself, without reaching upstream, kept so its host can name the
|
|
108
|
+
* cause instead of reading it back out of whatever the harness made of the answer (OSK-24521).
|
|
109
|
+
*/
|
|
110
|
+
export interface ManagedInferenceLocalRefusal {
|
|
111
|
+
code: typeof MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE | typeof MODEL_PROXY_ERROR.REQUEST_TOO_LARGE;
|
|
112
|
+
message: string;
|
|
113
|
+
}
|
|
85
114
|
export interface ManagedInferenceBrokerOptions {
|
|
86
115
|
credential: GatewayCredential;
|
|
116
|
+
/**
|
|
117
|
+
* OSK-24521 — send through this instead of authenticating with `credential.authToken`, which
|
|
118
|
+
* is then not required. `credential.baseUrl` still names the gateway every request goes to. Not
|
|
119
|
+
* combinable with the lease heartbeat (`leaseExpiresInMs`, `refreshCapability`), which renews a
|
|
120
|
+
* capability this source does not have.
|
|
121
|
+
*/
|
|
122
|
+
upstream?: ManagedInferenceUpstreamTransport;
|
|
123
|
+
/**
|
|
124
|
+
* The largest request body the listener buffers, when no lease envelope sets one
|
|
125
|
+
* (`modelScope.requestEnvelope.maxInputBytes` wins when present). Defaults to
|
|
126
|
+
* {@link MODEL_PROXY_MAX_BODY_BYTES}. A larger body is answered 413
|
|
127
|
+
* {@link MODEL_PROXY_ERROR.REQUEST_TOO_LARGE} before it is buffered, and kept as the session's
|
|
128
|
+
* {@link ManagedInferenceBrokerSession.localRefusal}.
|
|
129
|
+
*/
|
|
130
|
+
maxRequestBytes?: number;
|
|
87
131
|
/**
|
|
88
132
|
* OSK-3901 — remaining lease lifetime, in ms, at the moment the broker starts.
|
|
89
133
|
*
|
|
@@ -165,6 +209,12 @@ export interface ManagedInferenceBrokerSession {
|
|
|
165
209
|
clientModelId?: string;
|
|
166
210
|
/** Non-secret, validated lease policy used during the ACP setup handshake. */
|
|
167
211
|
reasoningPolicy?: ManagedReasoningPolicy;
|
|
212
|
+
/**
|
|
213
|
+
* The latest request this broker answered itself without reaching upstream, or null. Always
|
|
214
|
+
* present on a session this package starts; optional so a host's own double of a session (the
|
|
215
|
+
* daemon's tests build several) need not grow one.
|
|
216
|
+
*/
|
|
217
|
+
localRefusal?(): ManagedInferenceLocalRefusal | null;
|
|
168
218
|
stop(): Promise<void>;
|
|
169
219
|
}
|
|
170
220
|
/** A `loopback-tcp` broker: no socket, and no bearer in `env`. */
|
|
@@ -264,6 +314,52 @@ export declare function noProxyEnvWithHosts(env: Readonly<Record<string, string
|
|
|
264
314
|
};
|
|
265
315
|
export declare const MANAGED_SESSION_ENV = "OVERSKY_MANAGED_SESSION";
|
|
266
316
|
export declare const MANAGED_PROMPT_CACHING_ENV = "OVERSKY_MANAGED_PROMPT_CACHING";
|
|
317
|
+
/**
|
|
318
|
+
* The lease's input envelope, in the unit the relay enforces it (OSK-24550):
|
|
319
|
+
* `{"version":1,"maxInputTokens":N,"algorithm":"utf8_bytes_json_v1"|"openai_o200k_json_v1"}`.
|
|
320
|
+
*
|
|
321
|
+
* `maxInputTokens` is NOT a provider token count. The relay counts it with the
|
|
322
|
+
* reservation's `inputTokenAccounting` algorithm, and for every reviewed Claude
|
|
323
|
+
* model that is the request JSON's UTF-8 bytes plus a structural allowance, so
|
|
324
|
+
* 131,072 is about 33-46k real Claude tokens. The cap and its unit therefore
|
|
325
|
+
* travel together, from the one place that holds the validated lease: this
|
|
326
|
+
* broker, on both hosts (the daemon's routes and `skrr code`). A harness that
|
|
327
|
+
* reads only the number, and compares it with provider usage, never sees the
|
|
328
|
+
* refusal coming. That is how three Hosted Machine conversations ended in one
|
|
329
|
+
* week.
|
|
330
|
+
*
|
|
331
|
+
* Advisory to the child and grants nothing: the relay still refuses over it.
|
|
332
|
+
*/
|
|
333
|
+
export declare const MANAGED_INPUT_ENVELOPE_ENV = "OVERSKY_MANAGED_INPUT_ENVELOPE";
|
|
334
|
+
/** The value of `MANAGED_INPUT_ENVELOPE_ENV` for a validated model scope. */
|
|
335
|
+
export declare function managedInputEnvelopeValue(modelScope: ManagedInferenceModelScope): string;
|
|
336
|
+
/** A lease's input envelope as the broker advertises it: the cap and the unit it is counted in. */
|
|
337
|
+
export interface ManagedInputEnvelope {
|
|
338
|
+
/** Counted in `algorithm`'s unit, which is not a provider token for `utf8_bytes_json_v1`. */
|
|
339
|
+
readonly maxInputTokens: number;
|
|
340
|
+
readonly algorithm: ManagedInferenceInputTokenAccounting['algorithm'];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Read `MANAGED_INPUT_ENVELOPE_ENV` back (OSK-24550): the one reader of the
|
|
344
|
+
* value `managedInputEnvelopeValue` writes, for a daemon backend that hands a
|
|
345
|
+
* harness its limit in the harness's own unit. Anything it cannot read exactly
|
|
346
|
+
* (another version, a cap out of the lease's bounds, an unknown algorithm) is
|
|
347
|
+
* `undefined`, never a guess.
|
|
348
|
+
*/
|
|
349
|
+
export declare function parseManagedInputEnvelope(value: string | undefined): ManagedInputEnvelope | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* OSK-24521 — the status a request gets when the host's transport had no credential to send it
|
|
352
|
+
* with: 400, the one status the harnesses this answer reaches give up on at once. A credential
|
|
353
|
+
* the renewal could not produce is not one a retry a few seconds later will find, so a retried
|
|
354
|
+
* status only delays a turn that has already failed. Measured on the pinned Codex 0.169.0
|
|
355
|
+
* (`cloudHarness.codex.real.spec.js`): 400 ends the turn after 1 request in under 0.1 s, while
|
|
356
|
+
* 403, 409, 422 and 424 each take 6 requests and about 6 s, and 503 takes 30 requests and about
|
|
357
|
+
* 24 s. The AI SDK the first-party engine is built on retries 408, 409, 429 and every 5xx, and not
|
|
358
|
+
* 400. 401 is excluded because every harness reads it as a bad key. The body's
|
|
359
|
+
* `error.type` is `credential_unavailable`, so it is not mistaken for a malformed request, and the
|
|
360
|
+
* host names the cause from {@link ManagedInferenceBrokerSession.localRefusal}, not this status.
|
|
361
|
+
*/
|
|
362
|
+
export declare const CREDENTIAL_UNAVAILABLE_STATUS = 400;
|
|
267
363
|
export declare function managedClientModelId(scope: ManagedInferenceModelScope): string;
|
|
268
364
|
/** True only for a concrete gateway descriptor; raw provider keys never enter this broker. */
|
|
269
365
|
export declare function isGatewayCredential(value: unknown): value is Required<Pick<GatewayCredential, 'baseUrl' | 'authToken'>> & GatewayCredential;
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
13
13
|
import { chmodSync, chownSync, mkdtempSync, rmSync } from 'node:fs';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
|
-
import { ModelProxyLoopbackServer } from './loopback-server.js';
|
|
16
|
-
import { MODEL_PROXY_ERROR, ModelProxyError } from './contract.js';
|
|
15
|
+
import { ModelProxyLoopbackServer, RequestBodyTooLargeError, } from './loopback-server.js';
|
|
16
|
+
import { MODEL_PROXY_ERROR, MODEL_PROXY_MAX_BODY_BYTES, ModelProxyError } from './contract.js';
|
|
17
17
|
import { startRenewalLoop, } from './managed-inference-renewal.js';
|
|
18
18
|
const WITH_INFERENCE_BROKER_HOST_RE = /[\s,]+$/;
|
|
19
19
|
const BUILD_MANAGED_INFERENCE_RELAY_CREDENTIAL_RE = /\/$/;
|
|
@@ -93,6 +93,61 @@ function withNoProxyHosts(list, hosts) {
|
|
|
93
93
|
}
|
|
94
94
|
export const MANAGED_SESSION_ENV = 'OVERSKY_MANAGED_SESSION';
|
|
95
95
|
export const MANAGED_PROMPT_CACHING_ENV = 'OVERSKY_MANAGED_PROMPT_CACHING';
|
|
96
|
+
/**
|
|
97
|
+
* The lease's input envelope, in the unit the relay enforces it (OSK-24550):
|
|
98
|
+
* `{"version":1,"maxInputTokens":N,"algorithm":"utf8_bytes_json_v1"|"openai_o200k_json_v1"}`.
|
|
99
|
+
*
|
|
100
|
+
* `maxInputTokens` is NOT a provider token count. The relay counts it with the
|
|
101
|
+
* reservation's `inputTokenAccounting` algorithm, and for every reviewed Claude
|
|
102
|
+
* model that is the request JSON's UTF-8 bytes plus a structural allowance, so
|
|
103
|
+
* 131,072 is about 33-46k real Claude tokens. The cap and its unit therefore
|
|
104
|
+
* travel together, from the one place that holds the validated lease: this
|
|
105
|
+
* broker, on both hosts (the daemon's routes and `skrr code`). A harness that
|
|
106
|
+
* reads only the number, and compares it with provider usage, never sees the
|
|
107
|
+
* refusal coming. That is how three Hosted Machine conversations ended in one
|
|
108
|
+
* week.
|
|
109
|
+
*
|
|
110
|
+
* Advisory to the child and grants nothing: the relay still refuses over it.
|
|
111
|
+
*/
|
|
112
|
+
export const MANAGED_INPUT_ENVELOPE_ENV = 'OVERSKY_MANAGED_INPUT_ENVELOPE';
|
|
113
|
+
/** The value of `MANAGED_INPUT_ENVELOPE_ENV` for a validated model scope. */
|
|
114
|
+
export function managedInputEnvelopeValue(modelScope) {
|
|
115
|
+
return JSON.stringify({
|
|
116
|
+
version: 1,
|
|
117
|
+
maxInputTokens: modelScope.requestEnvelope.maxInputTokens,
|
|
118
|
+
algorithm: modelScope.inputTokenAccounting.algorithm,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Read `MANAGED_INPUT_ENVELOPE_ENV` back (OSK-24550): the one reader of the
|
|
123
|
+
* value `managedInputEnvelopeValue` writes, for a daemon backend that hands a
|
|
124
|
+
* harness its limit in the harness's own unit. Anything it cannot read exactly
|
|
125
|
+
* (another version, a cap out of the lease's bounds, an unknown algorithm) is
|
|
126
|
+
* `undefined`, never a guess.
|
|
127
|
+
*/
|
|
128
|
+
export function parseManagedInputEnvelope(value) {
|
|
129
|
+
if (!value)
|
|
130
|
+
return undefined;
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
parsed = JSON.parse(value);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
if (!parsed || typeof parsed !== 'object')
|
|
139
|
+
return undefined;
|
|
140
|
+
const { version, maxInputTokens, algorithm } = parsed;
|
|
141
|
+
if (version !== 1)
|
|
142
|
+
return undefined;
|
|
143
|
+
if (!Number.isSafeInteger(maxInputTokens) || Number(maxInputTokens) <= 0)
|
|
144
|
+
return undefined;
|
|
145
|
+
if (Number(maxInputTokens) > 1_000_000)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (algorithm !== 'utf8_bytes_json_v1' && algorithm !== 'openai_o200k_json_v1')
|
|
148
|
+
return undefined;
|
|
149
|
+
return { maxInputTokens: Number(maxInputTokens), algorithm };
|
|
150
|
+
}
|
|
96
151
|
const ALLOWED_PATHS = new Set([
|
|
97
152
|
'/v1/messages',
|
|
98
153
|
'/messages',
|
|
@@ -157,6 +212,36 @@ function countTokensUnavailableResponse() {
|
|
|
157
212
|
})(),
|
|
158
213
|
};
|
|
159
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* OSK-24521 — the status a request gets when the host's transport had no credential to send it
|
|
217
|
+
* with: 400, the one status the harnesses this answer reaches give up on at once. A credential
|
|
218
|
+
* the renewal could not produce is not one a retry a few seconds later will find, so a retried
|
|
219
|
+
* status only delays a turn that has already failed. Measured on the pinned Codex 0.169.0
|
|
220
|
+
* (`cloudHarness.codex.real.spec.js`): 400 ends the turn after 1 request in under 0.1 s, while
|
|
221
|
+
* 403, 409, 422 and 424 each take 6 requests and about 6 s, and 503 takes 30 requests and about
|
|
222
|
+
* 24 s. The AI SDK the first-party engine is built on retries 408, 409, 429 and every 5xx, and not
|
|
223
|
+
* 400. 401 is excluded because every harness reads it as a bad key. The body's
|
|
224
|
+
* `error.type` is `credential_unavailable`, so it is not mistaken for a malformed request, and the
|
|
225
|
+
* host names the cause from {@link ManagedInferenceBrokerSession.localRefusal}, not this status.
|
|
226
|
+
*/
|
|
227
|
+
export const CREDENTIAL_UNAVAILABLE_STATUS = 400;
|
|
228
|
+
function isCredentialUnavailable(error) {
|
|
229
|
+
return (error instanceof Error &&
|
|
230
|
+
error.code === MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE);
|
|
231
|
+
}
|
|
232
|
+
function credentialUnavailableResponse(message) {
|
|
233
|
+
const encoded = new TextEncoder().encode(JSON.stringify({
|
|
234
|
+
type: 'error',
|
|
235
|
+
error: { type: MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE, message },
|
|
236
|
+
}));
|
|
237
|
+
return {
|
|
238
|
+
status: CREDENTIAL_UNAVAILABLE_STATUS,
|
|
239
|
+
headers: { 'content-type': 'application/json', 'cache-control': 'no-store' },
|
|
240
|
+
body: (async function* () {
|
|
241
|
+
yield encoded;
|
|
242
|
+
})(),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
160
245
|
const FORWARDED_HEADERS = new Set([
|
|
161
246
|
'accept',
|
|
162
247
|
'content-type',
|
|
@@ -255,9 +340,23 @@ export async function startManagedInferenceBroker(options) {
|
|
|
255
340
|
const modelScope = isManagedInferenceModelScope(options.modelScope) ? options.modelScope : null;
|
|
256
341
|
const legacyModel = nonEmpty(options.model);
|
|
257
342
|
const promptCacheControl = options.promptCacheControl === 'strip' ? 'strip' : 'refuse';
|
|
258
|
-
|
|
343
|
+
const upstream = options.upstream ?? null;
|
|
344
|
+
if (upstream !== null && typeof upstream.send !== 'function') {
|
|
345
|
+
throw new Error('managed inference broker upstream transport has no send');
|
|
346
|
+
}
|
|
347
|
+
if (upstream && (options.leaseExpiresInMs !== undefined || options.refreshCapability)) {
|
|
348
|
+
// The heartbeat renews `authToken` against the relay; a transport upstream holds none.
|
|
349
|
+
throw new Error('managed inference broker upstream transport takes no lease heartbeat');
|
|
350
|
+
}
|
|
351
|
+
if (!gatewayBase || (!upstream && !gatewayKey) || (!modelScope && !legacyModel)) {
|
|
259
352
|
throw new Error('managed inference broker requires gateway base URL, virtual key, and resolved model');
|
|
260
353
|
}
|
|
354
|
+
const maxRequestBytes = options.maxRequestBytes ?? MODEL_PROXY_MAX_BODY_BYTES;
|
|
355
|
+
if (!Number.isSafeInteger(maxRequestBytes) || maxRequestBytes <= 0) {
|
|
356
|
+
throw new Error('managed inference broker maxRequestBytes must be a positive integer');
|
|
357
|
+
}
|
|
358
|
+
/** OSK-24521 — the latest request answered here without reaching upstream. */
|
|
359
|
+
let localRefusal = null;
|
|
261
360
|
let origin;
|
|
262
361
|
try {
|
|
263
362
|
origin = new URL(gatewayBase).origin;
|
|
@@ -268,7 +367,8 @@ export async function startManagedInferenceBroker(options) {
|
|
|
268
367
|
// 256-bit random, local-only bearer. It is meaningful solely to the
|
|
269
368
|
// loopback server and dies with this object; it is not accepted by LiteLLM.
|
|
270
369
|
let relayToken = randomBytes(32).toString('base64url');
|
|
271
|
-
|
|
370
|
+
// Empty for a transport upstream, which authenticates its own requests and is never sent this.
|
|
371
|
+
let upstreamKey = gatewayKey ?? '';
|
|
272
372
|
/**
|
|
273
373
|
* OSK-3901 — the lease renewal heartbeat, armed below once the session is up.
|
|
274
374
|
*
|
|
@@ -400,15 +500,37 @@ export async function startManagedInferenceBroker(options) {
|
|
|
400
500
|
if (FORWARDED_HEADERS.has(name.toLowerCase()))
|
|
401
501
|
headers.set(name, value);
|
|
402
502
|
}
|
|
403
|
-
|
|
404
|
-
|
|
503
|
+
// A transport upstream puts its own key on the request (OSK-24521).
|
|
504
|
+
if (!upstream)
|
|
505
|
+
headers.set('authorization', `Bearer ${upstreamKey}`);
|
|
506
|
+
const init = {
|
|
405
507
|
method: request.method,
|
|
406
508
|
headers,
|
|
509
|
+
// Buffered whole by the listener, so a transport may send these bytes a second time.
|
|
407
510
|
body: body ? body : undefined,
|
|
408
511
|
signal,
|
|
409
512
|
duplex: 'half',
|
|
410
513
|
redirect: 'error',
|
|
411
|
-
}
|
|
514
|
+
};
|
|
515
|
+
let response;
|
|
516
|
+
if (upstream) {
|
|
517
|
+
try {
|
|
518
|
+
response = await upstream.send(url.toString(), init);
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
if (!isCredentialUnavailable(error))
|
|
522
|
+
throw error;
|
|
523
|
+
localRefusal = {
|
|
524
|
+
code: MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE,
|
|
525
|
+
message: error.message || 'no upstream credential is available',
|
|
526
|
+
};
|
|
527
|
+
releaseSlot();
|
|
528
|
+
return credentialUnavailableResponse(localRefusal.message);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
response = await fetchImpl(url.toString(), init);
|
|
533
|
+
}
|
|
412
534
|
// OSK-3932 — learn the money from the response the session just made.
|
|
413
535
|
//
|
|
414
536
|
// The readout used to arrive only on the renewal heartbeat, and a read of
|
|
@@ -430,6 +552,15 @@ export async function startManagedInferenceBroker(options) {
|
|
|
430
552
|
}
|
|
431
553
|
},
|
|
432
554
|
};
|
|
555
|
+
// The lease envelope's bound when there is one, else the host's (OSK-24521), else the default.
|
|
556
|
+
const maxBodyBytes = envelope ? envelope.maxInputBytes : maxRequestBytes;
|
|
557
|
+
// A body over that bound is refused by the listener before it is buffered (413); kept here so
|
|
558
|
+
// the host can name it rather than infer it from the harness's reading of a 413.
|
|
559
|
+
const onListenerError = (error) => {
|
|
560
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
561
|
+
localRefusal = { code: MODEL_PROXY_ERROR.REQUEST_TOO_LARGE, message: error.message };
|
|
562
|
+
}
|
|
563
|
+
};
|
|
433
564
|
// The TCP transport has no file-mode fence, so the 256-bit relay token is the
|
|
434
565
|
// whole of its authentication. That is the same token the socket transport
|
|
435
566
|
// checks; the socket's 0600 mode is defence in depth this transport lacks.
|
|
@@ -440,7 +571,8 @@ export async function startManagedInferenceBroker(options) {
|
|
|
440
571
|
forwarder,
|
|
441
572
|
host: '127.0.0.1',
|
|
442
573
|
port: 0,
|
|
443
|
-
|
|
574
|
+
maxBodyBytes,
|
|
575
|
+
onError: onListenerError,
|
|
444
576
|
});
|
|
445
577
|
return { kind: 'tcp', server: tcp, origin: (await tcp.start()).baseUrl };
|
|
446
578
|
}
|
|
@@ -463,7 +595,8 @@ export async function startManagedInferenceBroker(options) {
|
|
|
463
595
|
socketPath: path,
|
|
464
596
|
...(sharedSocketGroup ? { socketGroupId: options.socketGroupId } : {}),
|
|
465
597
|
advertisedBaseUrl: INFERENCE_BROKER_ORIGIN,
|
|
466
|
-
|
|
598
|
+
maxBodyBytes,
|
|
599
|
+
onError: onListenerError,
|
|
467
600
|
});
|
|
468
601
|
try {
|
|
469
602
|
await socket.start();
|
|
@@ -574,7 +707,12 @@ export async function startManagedInferenceBroker(options) {
|
|
|
574
707
|
const promptCachingEnv = modelScope?.requestEnvelope.allowPromptCaching && supportsManagedPromptCaching(modelScope)
|
|
575
708
|
? { [MANAGED_PROMPT_CACHING_ENV]: '1' }
|
|
576
709
|
: {};
|
|
710
|
+
const leaseEnv = {
|
|
711
|
+
...promptCachingEnv,
|
|
712
|
+
...(modelScope ? { [MANAGED_INPUT_ENVELOPE_ENV]: managedInputEnvelopeValue(modelScope) } : {}),
|
|
713
|
+
};
|
|
577
714
|
const leaseFields = {
|
|
715
|
+
localRefusal: () => localRefusal,
|
|
578
716
|
...(modelScope ? { clientModelId: managedClientModelId(modelScope) } : {}),
|
|
579
717
|
...(envelope
|
|
580
718
|
? {
|
|
@@ -611,7 +749,7 @@ export async function startManagedInferenceBroker(options) {
|
|
|
611
749
|
return {
|
|
612
750
|
// No bearer and no base URL in the environment: a TCP harness is given the
|
|
613
751
|
// endpoint through its SDK, so nothing it starts inherits the token.
|
|
614
|
-
env: { [MANAGED_SESSION_ENV]: '1', ...
|
|
752
|
+
env: { [MANAGED_SESSION_ENV]: '1', ...leaseEnv },
|
|
615
753
|
endpoint: {
|
|
616
754
|
origin: listener.origin,
|
|
617
755
|
upstreamProvider: modelScope?.upstreamProvider ?? null,
|
|
@@ -645,7 +783,7 @@ export async function startManagedInferenceBroker(options) {
|
|
|
645
783
|
ANTHROPIC_AUTH_TOKEN: relayToken,
|
|
646
784
|
[INFERENCE_BROKER_SOCKET_ENV]: listener.path,
|
|
647
785
|
[MANAGED_SESSION_ENV]: '1',
|
|
648
|
-
...
|
|
786
|
+
...leaseEnv,
|
|
649
787
|
},
|
|
650
788
|
socketPath: listener.path,
|
|
651
789
|
...leaseFields,
|
package/oclif.manifest.json
CHANGED
|
@@ -150534,5 +150534,5 @@
|
|
|
150534
150534
|
]
|
|
150535
150535
|
}
|
|
150536
150536
|
},
|
|
150537
|
-
"version": "0.1.
|
|
150537
|
+
"version": "0.1.177"
|
|
150538
150538
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skrr-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.177",
|
|
4
4
|
"description": "Command-line interface for skrr",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "skrr",
|
|
@@ -704,5 +704,5 @@
|
|
|
704
704
|
"engines": {
|
|
705
705
|
"node": ">=20.0.0"
|
|
706
706
|
},
|
|
707
|
-
"gitHead": "
|
|
707
|
+
"gitHead": "79ec2041ae075c6e9da2b6533b9cb7c4d97c1b01"
|
|
708
708
|
}
|