@skrr-ai/cli 0.1.178 → 0.1.180
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/code/index.js +5 -0
- package/dist/commands/diagnostics/inference-smoke.d.ts +13 -0
- package/dist/commands/diagnostics/inference-smoke.js +50 -0
- package/dist/commands/harnesses/evaluations/evidence.d.ts +22 -0
- package/dist/commands/harnesses/evaluations/evidence.js +92 -0
- package/dist/commands/harnesses/evaluations/fixed-tool.d.ts +10 -0
- package/dist/commands/harnesses/evaluations/fixed-tool.js +189 -0
- package/dist/commands/harnesses/evaluations/grant.d.ts +30 -0
- package/dist/commands/harnesses/evaluations/grant.js +109 -0
- package/dist/commands/harnesses/evaluations/list.d.ts +18 -0
- package/dist/commands/harnesses/evaluations/list.js +73 -0
- package/dist/commands/harnesses/evaluations/platform-h9-turn.d.ts +13 -0
- package/dist/commands/harnesses/evaluations/platform-h9-turn.js +322 -0
- package/dist/commands/harnesses/evaluations/revoke.d.ts +19 -0
- package/dist/commands/harnesses/evaluations/revoke.js +45 -0
- package/dist/commands/harnesses/evaluations/show.d.ts +14 -0
- package/dist/commands/harnesses/evaluations/show.js +46 -0
- package/dist/commands/harnesses/list.d.ts +1 -0
- package/dist/commands/harnesses/list.js +11 -2
- package/dist/commands/harnesses/show.js +5 -0
- package/dist/commands/machines/hosted/identity-evaluations/issue.d.ts +12 -0
- package/dist/commands/machines/hosted/identity-evaluations/issue.js +40 -0
- package/dist/commands/machines/hosted/identity-evaluations/revoke.d.ts +11 -0
- package/dist/commands/machines/hosted/identity-evaluations/revoke.js +21 -0
- package/dist/commands/machines/hosted/identity-evaluations/show.d.ts +8 -0
- package/dist/commands/machines/hosted/identity-evaluations/show.js +20 -0
- package/dist/commands/machines/hosted/start.d.ts +1 -0
- package/dist/commands/machines/hosted/start.js +6 -0
- package/dist/lib/agentic-stream.d.ts +3 -0
- package/dist/lib/agentic-stream.js +63 -1
- package/dist/lib/copilot-fixed-probe-runner.d.ts +72 -0
- package/dist/lib/copilot-fixed-probe-runner.js +213 -0
- package/dist/lib/copilot-fixed-probe.d.ts +61 -0
- package/dist/lib/copilot-fixed-probe.js +223 -0
- package/dist/lib/first-party-harness-broker.d.ts +5 -0
- package/dist/lib/first-party-harness-broker.js +99 -0
- package/dist/lib/h9-platform-stream.d.ts +63 -0
- package/dist/lib/h9-platform-stream.js +317 -0
- package/dist/lib/h9-prior-stream.d.ts +44 -0
- package/dist/lib/h9-prior-stream.js +217 -0
- package/dist/lib/harness-evaluations.d.ts +251 -0
- package/dist/lib/harness-evaluations.js +66 -0
- package/dist/lib/harness-labels.d.ts +10 -0
- package/dist/lib/harness-labels.js +23 -0
- package/dist/lib/hosted-identity-evaluations.d.ts +26 -0
- package/dist/lib/hosted-identity-evaluations.js +18 -0
- package/dist/lib/hosted-machines.d.ts +1 -0
- package/dist/lib/inference-overload-smoke-contract.d.ts +53 -0
- package/dist/lib/inference-overload-smoke-contract.js +192 -0
- package/dist/lib/inference-overload-smoke.d.ts +78 -0
- package/dist/lib/inference-overload-smoke.js +350 -0
- package/dist/lib/operator-probe-files.d.ts +6 -0
- package/dist/lib/operator-probe-files.js +68 -0
- package/dist/lib/platform-h9-plan.d.ts +47 -0
- package/dist/lib/platform-h9-plan.js +78 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/codex-model-catalog.json +150 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.d.ts +12 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/inferenceBrokerHarnesses.js +12 -5
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.d.ts +12 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/inferenceBrokerHarnesses.js +21 -7
- package/dist/node_modules/@skrr-ai/data-provider/index.js +6 -6
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/index.js +23 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-haiku-none.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-haiku-none.js +40 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.d.ts +11 -20
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/managed-inference-broker.js +88 -9
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/overload-smoke.d.ts +56 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/cjs/overload-smoke.js +277 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/index.js +3 -1
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-haiku-none.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-haiku-none.js +20 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.d.ts +11 -20
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/managed-inference-broker.js +105 -12
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/overload-smoke.d.ts +56 -0
- package/dist/node_modules/@skrr-ai/inference-broker/dist/esm/overload-smoke.js +261 -0
- package/oclif.manifest.json +1391 -443
- package/package.json +5 -2
|
@@ -51,10 +51,12 @@
|
|
|
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_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, CREDENTIAL_UNAVAILABLE_STATUS, } from './managed-inference-broker.js';
|
|
54
|
+
export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, CREDENTIAL_UNAVAILABLE_STATUS, } 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
|
|
58
58
|
// pure re-export of this module: 23 daemon files import that path today, and
|
|
59
59
|
// keeping it a re-export means none of them change.
|
|
60
60
|
export * from './contract.js';
|
|
61
|
+
export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits } from './overload-smoke.js';
|
|
62
|
+
export { projectManagedHaiku45None } from './managed-haiku-none.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Native Haiku4.5 accepts thinking.disabled, not a named output_config effort. Project
|
|
2
|
+
* the already-admitted NONE in that exact dialect; never change the immutable lease.
|
|
3
|
+
* All other models/providers/efforts retain their existing transport behavior. */
|
|
4
|
+
export declare function projectManagedHaiku45None(payload: Record<string, unknown>, options: {
|
|
5
|
+
model: string;
|
|
6
|
+
upstreamProvider: string;
|
|
7
|
+
effort: string;
|
|
8
|
+
}): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Native Haiku4.5 accepts thinking.disabled, not a named output_config effort. Project
|
|
2
|
+
* the already-admitted NONE in that exact dialect; never change the immutable lease.
|
|
3
|
+
* All other models/providers/efforts retain their existing transport behavior. */
|
|
4
|
+
export function projectManagedHaiku45None(payload, options) {
|
|
5
|
+
if (options.upstreamProvider !== 'anthropic' || options.effort !== 'none' ||
|
|
6
|
+
!['claude-haiku-4-5', 'anthropic/claude-haiku-4-5'].includes(options.model))
|
|
7
|
+
return false;
|
|
8
|
+
const thinking = payload.thinking;
|
|
9
|
+
if (thinking != null && (!thinking || typeof thinking !== 'object' || Array.isArray(thinking) ||
|
|
10
|
+
Object.keys(thinking).length !== 1 || thinking.type !== 'disabled'))
|
|
11
|
+
throw new Error('managed Haiku NONE conflicts with thinking');
|
|
12
|
+
const output = payload.output_config;
|
|
13
|
+
if (output != null && (!output || typeof output !== 'object' || Array.isArray(output) ||
|
|
14
|
+
Object.keys(output).some(key => key !== 'effort') ||
|
|
15
|
+
(output.effort != null && output.effort !== 'none')))
|
|
16
|
+
throw new Error('managed Haiku NONE conflicts with output config');
|
|
17
|
+
delete payload.output_config;
|
|
18
|
+
payload.thinking = { type: 'disabled' };
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* First-party managed-inference broker for skrr Code.
|
|
3
|
-
*
|
|
4
|
-
* A LiteLLM virtual key is still a bearer capability. Delivering it through
|
|
5
|
-
* an ACP child's environment would make it available to the harness, its
|
|
6
|
-
* descendants, crash dumps, and the default wrapper's serialized request.
|
|
7
|
-
* For the first-party runtime the server retains that key behind an
|
|
8
|
-
* authenticated public relay. The daemon exposes a per-session Unix loopback
|
|
9
|
-
* endpoint, and the child receives only a random secret usable against that
|
|
10
|
-
* endpoint while it is alive.
|
|
11
|
-
*/
|
|
12
1
|
import { MODEL_PROXY_ERROR } from './contract.js';
|
|
13
2
|
import { type CapabilityRefreshOutcome, type RenewalOutcome, type RenewalStopReason } from './managed-inference-renewal.js';
|
|
3
|
+
/** Reviewed OpenAI models that accept explicit-only caching. */
|
|
4
|
+
export declare function supportsOpenAIExplicitPromptCache(modelId: unknown): boolean;
|
|
14
5
|
type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
15
6
|
export interface GatewayCredential {
|
|
16
7
|
baseUrl?: string;
|
|
@@ -171,15 +162,15 @@ export interface ManagedInferenceBrokerOptions {
|
|
|
171
162
|
*/
|
|
172
163
|
transport?: ManagedInferenceBrokerTransport;
|
|
173
164
|
/**
|
|
174
|
-
* What
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
165
|
+
* What the broker does with an Anthropic-dialect `cache_control` marker the
|
|
166
|
+
* lease does not admit. `refuse` (the default) fails the request. `strip`
|
|
167
|
+
* forwards it within the lease instead, for a harness that always sends the
|
|
168
|
+
* markers and cannot be told not to (Claude Code, OSK-24457): under a lease
|
|
169
|
+
* that does NOT allow caching every marker is removed; under a Claude lease
|
|
170
|
+
* 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
|
|
172
|
+
* contract after that is forwarded uncached. Stripping can only lower what a
|
|
173
|
+
* request costs. Every other prompt-cache field is still refused.
|
|
183
174
|
*/
|
|
184
175
|
promptCacheControl?: 'refuse' | 'strip';
|
|
185
176
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { projectManagedHaiku45None } from './managed-haiku-none.js';
|
|
1
2
|
/**
|
|
2
3
|
* First-party managed-inference broker for skrr Code.
|
|
3
4
|
*
|
|
@@ -19,6 +20,20 @@ const WITH_INFERENCE_BROKER_HOST_RE = /[\s,]+$/;
|
|
|
19
20
|
const BUILD_MANAGED_INFERENCE_RELAY_CREDENTIAL_RE = /\/$/;
|
|
20
21
|
const START_MANAGED_INFERENCE_BROKER_RE = /\/+$/;
|
|
21
22
|
const SUPPORTS_MANAGED_PROMPT_CACHING_RE = /^openai\//;
|
|
23
|
+
const CURRENT_OPENAI_CACHE_MODELS = new Set([
|
|
24
|
+
'gpt-6-luna',
|
|
25
|
+
'gpt-6.1-terra',
|
|
26
|
+
'gpt-6.2-astra',
|
|
27
|
+
'gpt-6.2-sol',
|
|
28
|
+
]);
|
|
29
|
+
/** Reviewed OpenAI models that accept explicit-only caching. */
|
|
30
|
+
export function supportsOpenAIExplicitPromptCache(modelId) {
|
|
31
|
+
if (typeof modelId !== 'string')
|
|
32
|
+
return false;
|
|
33
|
+
const model = modelId.trim().toLowerCase()
|
|
34
|
+
.replace(/^(?:openai\/|(?:(?:bedrock_mantle|bedrock|amazon-bedrock)\/)?openai\.)/, '');
|
|
35
|
+
return /(?:^|[/.])gpt-5\.6(?:-|$)/.test(model) || CURRENT_OPENAI_CACHE_MODELS.has(model);
|
|
36
|
+
}
|
|
22
37
|
// A synthetic origin is required by URL-oriented provider SDKs. skrr Code pairs
|
|
23
38
|
// it with OVERSKY_INFERENCE_BROKER_SOCKET and Bun's `fetch({ unix })`; it is
|
|
24
39
|
// never resolved through DNS or connected over TCP.
|
|
@@ -1113,10 +1128,19 @@ function enforceRequestEnvelope(payload, path, envelope, modelScope, promptCache
|
|
|
1113
1128
|
};
|
|
1114
1129
|
}
|
|
1115
1130
|
else if (path.endsWith('/messages')) {
|
|
1116
|
-
|
|
1131
|
+
let noThinking = false;
|
|
1132
|
+
try {
|
|
1133
|
+
noThinking = projectManagedHaiku45None(payload, { model: modelScope.harnessModelId,
|
|
1134
|
+
upstreamProvider: modelScope.upstreamProvider, effort: effectiveEffort });
|
|
1135
|
+
}
|
|
1136
|
+
catch {
|
|
1137
|
+
rejectManagedRequest('managed Haiku NONE conflicts with thinking or output config');
|
|
1138
|
+
}
|
|
1139
|
+
if (!noThinking && !['low', 'medium', 'high', 'max'].includes(effectiveEffort)) {
|
|
1117
1140
|
rejectManagedRequest('managed inference broker denied reasoning effort unsupported by the Anthropic dialect');
|
|
1118
1141
|
}
|
|
1119
|
-
|
|
1142
|
+
if (!noThinking)
|
|
1143
|
+
payload.output_config = { ...(anthropicOutputConfig ?? {}), effort: effectiveEffort };
|
|
1120
1144
|
}
|
|
1121
1145
|
else if (modelScope.upstreamProvider === 'openrouter') {
|
|
1122
1146
|
// OpenRouter accepts either reasoning.effort or reasoning.max_tokens,
|
|
@@ -1189,14 +1213,66 @@ function isPlainObject(value) {
|
|
|
1189
1213
|
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
1190
1214
|
}
|
|
1191
1215
|
const MAX_OPENAI_CACHE_BREAKPOINTS = 50;
|
|
1192
|
-
|
|
1216
|
+
/**
|
|
1217
|
+
* The Claude prompt-cache contract (OSK-24595), the same one the API relay
|
|
1218
|
+
* enforces (`managedPromptCacheAuthority.js`): `cache_control` of type
|
|
1219
|
+
* `ephemeral`, a 5-minute TTL (the only write the reservation floor prices),
|
|
1220
|
+
* at most four breakpoints (Anthropic's limit, automatic caching included).
|
|
1221
|
+
*/
|
|
1222
|
+
const CLAUDE_PROMPT_CACHE_TTL = '5m';
|
|
1223
|
+
const CLAUDE_MAX_CACHE_BREAKPOINTS = 4;
|
|
1224
|
+
/**
|
|
1225
|
+
* The upstreams a Claude caching lease is honoured on. OpenRouter is absent on
|
|
1226
|
+
* purpose: it picks the serving endpoint per request, so its cache price and
|
|
1227
|
+
* retention are not reviewed, and the server never issues such a lease.
|
|
1228
|
+
*/
|
|
1229
|
+
const CLAUDE_PROMPT_CACHE_UPSTREAMS = ['anthropic', 'bedrock'];
|
|
1230
|
+
/** Which reviewed cache contract a lease's model speaks, or null when none. */
|
|
1231
|
+
function managedPromptCacheContract(modelScope) {
|
|
1193
1232
|
const model = nonEmpty(modelScope.wireModel)
|
|
1194
1233
|
?.replace(SUPPORTS_MANAGED_PROMPT_CACHING_RE, '')
|
|
1195
1234
|
.toLowerCase();
|
|
1196
|
-
|
|
1235
|
+
if (modelScope.upstreamProvider === 'openai' && supportsOpenAIExplicitPromptCache(modelScope.wireModel))
|
|
1236
|
+
return 'openai';
|
|
1237
|
+
if (CLAUDE_PROMPT_CACHE_UPSTREAMS.includes(modelScope.upstreamProvider) &&
|
|
1238
|
+
model?.includes('claude')) {
|
|
1239
|
+
return 'claude';
|
|
1240
|
+
}
|
|
1241
|
+
return null;
|
|
1242
|
+
}
|
|
1243
|
+
function supportsManagedPromptCaching(modelScope) {
|
|
1244
|
+
return managedPromptCacheContract(modelScope) !== null;
|
|
1245
|
+
}
|
|
1246
|
+
/** Why a request's `cache_control` markers fall outside the Claude contract, or null. */
|
|
1247
|
+
function claudeCacheControlViolation(payload) {
|
|
1248
|
+
const controls = objectKeyValues(payload, 'cache_control');
|
|
1249
|
+
if (controls.length > CLAUDE_MAX_CACHE_BREAKPOINTS) {
|
|
1250
|
+
return `at most ${CLAUDE_MAX_CACHE_BREAKPOINTS} cache_control breakpoints are allowed`;
|
|
1251
|
+
}
|
|
1252
|
+
for (const control of controls) {
|
|
1253
|
+
if (!isPlainObject(control))
|
|
1254
|
+
return 'cache_control must be an object';
|
|
1255
|
+
if (Object.keys(control).some((key) => key !== 'type' && key !== 'ttl')) {
|
|
1256
|
+
return 'cache_control accepts only type and ttl';
|
|
1257
|
+
}
|
|
1258
|
+
if (control.type !== 'ephemeral')
|
|
1259
|
+
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}`;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return null;
|
|
1265
|
+
}
|
|
1266
|
+
/** Drop every `ttl` that is not the priced one, so the write falls back to 5 minutes. */
|
|
1267
|
+
function normalizeClaudeCacheTtl(payload) {
|
|
1268
|
+
for (const control of objectKeyValues(payload, 'cache_control')) {
|
|
1269
|
+
if (isPlainObject(control) && control.ttl != null && control.ttl !== CLAUDE_PROMPT_CACHE_TTL) {
|
|
1270
|
+
delete control.ttl;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1197
1273
|
}
|
|
1198
1274
|
/**
|
|
1199
|
-
* OpenAI
|
|
1275
|
+
* OpenAI caching is implicit by default on models with this contract; removing the SDK's routing
|
|
1200
1276
|
* key does not disable it. A disabled lease is normalized to the provider's
|
|
1201
1277
|
* explicit/no-breakpoint contract before the request reaches the public relay.
|
|
1202
1278
|
* The authenticated API repeats this enforcement for direct capability calls.
|
|
@@ -1210,21 +1286,38 @@ function enforcePromptCacheEnvelope(payload, envelope, modelScope, promptCacheCo
|
|
|
1210
1286
|
const claudeCacheControlFamily = ['anthropic', 'openrouter', 'bedrock'].includes(modelScope.upstreamProvider) &&
|
|
1211
1287
|
model?.includes('claude');
|
|
1212
1288
|
if (claudeCacheControlFamily) {
|
|
1289
|
+
const openAICacheFields = containsObjectKey(payload, 'prompt_cache_breakpoint') ||
|
|
1290
|
+
payload.prompt_cache_key != null ||
|
|
1291
|
+
payload.prompt_cache_options != null ||
|
|
1292
|
+
payload.prompt_cache_retention != null;
|
|
1213
1293
|
if (envelope.allowPromptCaching) {
|
|
1214
|
-
|
|
1294
|
+
// OSK-24595: a Claude lease that allows caching admits `cache_control`
|
|
1295
|
+
// within the reviewed contract. The relay checks the same contract again.
|
|
1296
|
+
if (managedPromptCacheContract(modelScope) !== 'claude') {
|
|
1297
|
+
rejectManagedRequest('managed inference broker has no prompt cache policy for the leased model');
|
|
1298
|
+
}
|
|
1299
|
+
if (openAICacheFields) {
|
|
1300
|
+
rejectManagedRequest('managed inference broker denied a prompt cache field Claude caching does not use');
|
|
1301
|
+
}
|
|
1302
|
+
if (promptCacheControl === 'strip') {
|
|
1303
|
+
normalizeClaudeCacheTtl(payload);
|
|
1304
|
+
if (claudeCacheControlViolation(payload))
|
|
1305
|
+
deleteObjectKey(payload, 'cache_control');
|
|
1306
|
+
}
|
|
1307
|
+
const violation = claudeCacheControlViolation(payload);
|
|
1308
|
+
if (violation) {
|
|
1309
|
+
rejectManagedRequest(`managed inference broker denied prompt caching: ${violation}`);
|
|
1310
|
+
}
|
|
1311
|
+
return;
|
|
1215
1312
|
}
|
|
1216
1313
|
if (promptCacheControl === 'strip')
|
|
1217
1314
|
deleteObjectKey(payload, 'cache_control');
|
|
1218
|
-
if (containsObjectKey(payload, 'cache_control') ||
|
|
1219
|
-
containsObjectKey(payload, 'prompt_cache_breakpoint') ||
|
|
1220
|
-
payload.prompt_cache_key != null ||
|
|
1221
|
-
payload.prompt_cache_options != null ||
|
|
1222
|
-
payload.prompt_cache_retention != null) {
|
|
1315
|
+
if (containsObjectKey(payload, 'cache_control') || openAICacheFields) {
|
|
1223
1316
|
rejectManagedRequest('managed inference broker denied prompt caching outside the lease envelope');
|
|
1224
1317
|
}
|
|
1225
1318
|
return;
|
|
1226
1319
|
}
|
|
1227
|
-
if (
|
|
1320
|
+
if (managedPromptCacheContract(modelScope) !== 'openai') {
|
|
1228
1321
|
rejectManagedRequest('managed inference broker has no prompt cache policy for the leased model');
|
|
1229
1322
|
}
|
|
1230
1323
|
const breakpoints = objectKeyValues(payload, 'prompt_cache_breakpoint');
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Fixed synthetic inference smoke contract. No caller-configurable workload or authority. */
|
|
2
|
+
export declare const OVERLOAD_SMOKE_PLAN: Readonly<{
|
|
3
|
+
version: 1;
|
|
4
|
+
total: 128;
|
|
5
|
+
baseline: 32;
|
|
6
|
+
mixedNative: 32;
|
|
7
|
+
nativeCount: 64;
|
|
8
|
+
batch: 64;
|
|
9
|
+
durationMs: 180000;
|
|
10
|
+
nativeSpacingMs: 2100;
|
|
11
|
+
maxOutputTokens: 16;
|
|
12
|
+
maxInputUnits: 1024;
|
|
13
|
+
maxResponseBytes: 65536;
|
|
14
|
+
nativeOrdinalWaitMs: 10000;
|
|
15
|
+
nativeOrdinalPollMs: 250;
|
|
16
|
+
alias: "claude-haiku-4-5";
|
|
17
|
+
nativeModel: "anthropic/claude-haiku-4-5";
|
|
18
|
+
purpose: "utility.diagnostics.overload";
|
|
19
|
+
feature: "inference-overload-smoke";
|
|
20
|
+
providerExposurePerSendUsd: 0.0023184;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function overloadSmokeError(code: string): Error & {
|
|
23
|
+
code: string;
|
|
24
|
+
};
|
|
25
|
+
/** utf8_bytes_json_v1 input bound, not provider token usage. API parity controls hold this
|
|
26
|
+
* equal to the existing authoritative native accounting strategy for these fixed JSON bodies. */
|
|
27
|
+
export declare function countAnthropicSmokeInputUnits(body: unknown): number;
|
|
28
|
+
export declare function overloadSmokePrompt(index: number): string;
|
|
29
|
+
export declare function overloadSmokeNativePayload(index: number, modelSelector?: string): {
|
|
30
|
+
model: string;
|
|
31
|
+
max_tokens: 16;
|
|
32
|
+
stream: boolean;
|
|
33
|
+
messages: {
|
|
34
|
+
role: string;
|
|
35
|
+
content: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
export declare function boundedOverloadSmokeBody(body: any, expectedPrompt: string): number;
|
|
39
|
+
type NativeReceiptUpstream = {
|
|
40
|
+
status: number;
|
|
41
|
+
body: {
|
|
42
|
+
getReader(): Pick<ReadableStreamDefaultReader<Uint8Array>, 'read' | 'cancel'>;
|
|
43
|
+
} | null;
|
|
44
|
+
};
|
|
45
|
+
/** Consume the real native Messages stream; retain metadata only, never generated text. */
|
|
46
|
+
export declare function readOverloadSmokeNativeReceipt(upstream: NativeReceiptUpstream, signal: AbortSignal, now: () => number, started: number): Promise<{
|
|
47
|
+
tokens: {
|
|
48
|
+
input: number;
|
|
49
|
+
output: number;
|
|
50
|
+
};
|
|
51
|
+
responseId: never;
|
|
52
|
+
reportedModel: null;
|
|
53
|
+
firstByteMs: number | null;
|
|
54
|
+
}>;
|
|
55
|
+
export declare function boundedOverloadSmokeResponse(response: Response, signal: AbortSignal): Promise<Response>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/** Fixed synthetic inference smoke contract. No caller-configurable workload or authority. */
|
|
2
|
+
export const OVERLOAD_SMOKE_PLAN = Object.freeze({
|
|
3
|
+
version: 1, total: 128, baseline: 32, mixedNative: 32, nativeCount: 64, batch: 64,
|
|
4
|
+
durationMs: 180000, nativeSpacingMs: 2100, maxOutputTokens: 16, maxInputUnits: 1024,
|
|
5
|
+
maxResponseBytes: 65536, nativeOrdinalWaitMs: 10000, nativeOrdinalPollMs: 250,
|
|
6
|
+
alias: 'claude-haiku-4-5', nativeModel: 'anthropic/claude-haiku-4-5',
|
|
7
|
+
purpose: 'utility.diagnostics.overload', feature: 'inference-overload-smoke',
|
|
8
|
+
providerExposurePerSendUsd: 0.0023184,
|
|
9
|
+
});
|
|
10
|
+
const LIMITS = OVERLOAD_SMOKE_PLAN;
|
|
11
|
+
const ALIAS = OVERLOAD_SMOKE_PLAN.alias;
|
|
12
|
+
export function overloadSmokeError(code) {
|
|
13
|
+
return Object.assign(new Error(code), { code });
|
|
14
|
+
}
|
|
15
|
+
const refusal = overloadSmokeError;
|
|
16
|
+
/** utf8_bytes_json_v1 input bound, not provider token usage. API parity controls hold this
|
|
17
|
+
* equal to the existing authoritative native accounting strategy for these fixed JSON bodies. */
|
|
18
|
+
export function countAnthropicSmokeInputUnits(body) {
|
|
19
|
+
let serialized;
|
|
20
|
+
try {
|
|
21
|
+
serialized = JSON.stringify(body);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw refusal('SMOKE_WIRE_CHANGED');
|
|
25
|
+
}
|
|
26
|
+
if (!serialized)
|
|
27
|
+
throw refusal('SMOKE_WIRE_CHANGED');
|
|
28
|
+
let containers = 0;
|
|
29
|
+
const pending = [body];
|
|
30
|
+
while (pending.length) {
|
|
31
|
+
const value = pending.pop();
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
containers += 1 + value.length;
|
|
34
|
+
pending.push(...value);
|
|
35
|
+
}
|
|
36
|
+
else if (value && typeof value === 'object') {
|
|
37
|
+
containers += 1;
|
|
38
|
+
pending.push(...Object.values(value));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Buffer.byteLength(serialized, 'utf8') + 256 + containers * 4;
|
|
42
|
+
}
|
|
43
|
+
function integer(value) {
|
|
44
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
45
|
+
}
|
|
46
|
+
export function overloadSmokePrompt(index) {
|
|
47
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= 128)
|
|
48
|
+
throw refusal('SMOKE_INDEX_INVALID');
|
|
49
|
+
return `Reply only OK. OSK24476 synthetic probe ${String(index).padStart(3, '0')}.`;
|
|
50
|
+
}
|
|
51
|
+
export function overloadSmokeNativePayload(index, modelSelector = ALIAS) {
|
|
52
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= 64)
|
|
53
|
+
throw refusal('SMOKE_INDEX_INVALID');
|
|
54
|
+
return {
|
|
55
|
+
model: modelSelector,
|
|
56
|
+
max_tokens: LIMITS.maxOutputTokens,
|
|
57
|
+
stream: true,
|
|
58
|
+
messages: [{ role: 'user', content: overloadSmokePrompt(index) }],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function boundedOverloadSmokeBody(body, expectedPrompt) {
|
|
62
|
+
const allowed = new Set([
|
|
63
|
+
'model',
|
|
64
|
+
'max_tokens',
|
|
65
|
+
'messages',
|
|
66
|
+
'stream',
|
|
67
|
+
'temperature',
|
|
68
|
+
'top_p',
|
|
69
|
+
'top_k',
|
|
70
|
+
'stop_sequences',
|
|
71
|
+
'thinking',
|
|
72
|
+
]);
|
|
73
|
+
if (!body ||
|
|
74
|
+
Object.keys(body).some((key) => !allowed.has(key)) ||
|
|
75
|
+
![ALIAS, OVERLOAD_SMOKE_PLAN.nativeModel].includes(body.model) ||
|
|
76
|
+
body.max_tokens !== LIMITS.maxOutputTokens ||
|
|
77
|
+
body.messages?.length !== 1 ||
|
|
78
|
+
body.messages[0].role !== 'user' ||
|
|
79
|
+
body.tools != null ||
|
|
80
|
+
body.system != null ||
|
|
81
|
+
body.output_config != null ||
|
|
82
|
+
(body.thinking != null &&
|
|
83
|
+
(body.thinking.type !== 'disabled' || Object.keys(body.thinking).length !== 1)))
|
|
84
|
+
throw refusal('SMOKE_WIRE_CHANGED');
|
|
85
|
+
const content = body.messages[0].content;
|
|
86
|
+
const text = typeof content === 'string'
|
|
87
|
+
? content
|
|
88
|
+
: Array.isArray(content) &&
|
|
89
|
+
content.length === 1 &&
|
|
90
|
+
content[0].type === 'text' &&
|
|
91
|
+
Object.keys(content[0]).every((key) => ['type', 'text'].includes(key))
|
|
92
|
+
? content[0].text
|
|
93
|
+
: null;
|
|
94
|
+
if (text !== expectedPrompt)
|
|
95
|
+
throw refusal('SMOKE_WIRE_CHANGED');
|
|
96
|
+
const units = countAnthropicSmokeInputUnits(body);
|
|
97
|
+
if (units > LIMITS.maxInputUnits)
|
|
98
|
+
throw refusal('SMOKE_INPUT_BOUND');
|
|
99
|
+
return units;
|
|
100
|
+
}
|
|
101
|
+
function checkedUsage(usage) {
|
|
102
|
+
const input = usage?.input_tokens ?? usage?.inputTokens ?? usage?.input;
|
|
103
|
+
const output = usage?.output_tokens ?? usage?.outputTokens ?? usage?.output;
|
|
104
|
+
if (!integer(input) ||
|
|
105
|
+
!integer(output) ||
|
|
106
|
+
input > LIMITS.maxInputUnits ||
|
|
107
|
+
output > LIMITS.maxOutputTokens ||
|
|
108
|
+
usage.cache_creation_input_tokens ||
|
|
109
|
+
usage.cache_read_input_tokens)
|
|
110
|
+
throw refusal('SMOKE_USAGE_UNKNOWN');
|
|
111
|
+
return { input, output };
|
|
112
|
+
}
|
|
113
|
+
/** Consume the real native Messages stream; retain metadata only, never generated text. */
|
|
114
|
+
export async function readOverloadSmokeNativeReceipt(upstream, signal, now, started) {
|
|
115
|
+
if (upstream.status !== 200)
|
|
116
|
+
throw refusal(`SMOKE_NATIVE_HTTP_${upstream.status}`);
|
|
117
|
+
const reader = upstream.body?.getReader();
|
|
118
|
+
if (!reader)
|
|
119
|
+
throw refusal('SMOKE_NATIVE_STREAM_MISSING');
|
|
120
|
+
let buffer = '';
|
|
121
|
+
let bytes = 0;
|
|
122
|
+
let firstByteMs = null;
|
|
123
|
+
let stopped = false;
|
|
124
|
+
let stopReason = null;
|
|
125
|
+
let input = null;
|
|
126
|
+
let output = null;
|
|
127
|
+
let responseId = null;
|
|
128
|
+
let reportedModel = null;
|
|
129
|
+
const decoder = new TextDecoder();
|
|
130
|
+
const consume = (frame) => {
|
|
131
|
+
const data = frame
|
|
132
|
+
.split(/\r?\n/)
|
|
133
|
+
.filter((line) => line.startsWith('data:'))
|
|
134
|
+
.map((line) => line.slice(5).trim())
|
|
135
|
+
.join('\n');
|
|
136
|
+
if (!data)
|
|
137
|
+
return;
|
|
138
|
+
let event;
|
|
139
|
+
try {
|
|
140
|
+
event = JSON.parse(data);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
throw refusal('SMOKE_NATIVE_STREAM_INVALID');
|
|
144
|
+
}
|
|
145
|
+
if (event.type === 'message_start') {
|
|
146
|
+
if (input !== null)
|
|
147
|
+
throw refusal('SMOKE_NATIVE_MULTIPLE_RESPONSES');
|
|
148
|
+
const usage = checkedUsage({
|
|
149
|
+
...event.message?.usage,
|
|
150
|
+
output_tokens: event.message?.usage?.output_tokens ?? 0,
|
|
151
|
+
});
|
|
152
|
+
input = usage.input;
|
|
153
|
+
output = usage.output;
|
|
154
|
+
responseId = typeof event.message?.id === 'string' && /^msg[-_A-Za-z0-9:.]{1,188}$/.test(event.message.id) ? event.message.id : null;
|
|
155
|
+
reportedModel = typeof event.message?.model === 'string' && /^(?:anthropic\/)?claude-haiku-4-5(?:-20251001)?$/.test(event.message.model) ? event.message.model : null;
|
|
156
|
+
}
|
|
157
|
+
if (event.type === 'message_delta') {
|
|
158
|
+
if (!integer(event.usage?.output_tokens))
|
|
159
|
+
throw refusal('SMOKE_USAGE_UNKNOWN');
|
|
160
|
+
output = event.usage.output_tokens;
|
|
161
|
+
stopReason = event.delta?.stop_reason;
|
|
162
|
+
}
|
|
163
|
+
if (event.type === 'message_stop')
|
|
164
|
+
stopped = true;
|
|
165
|
+
if (event.type === 'error' ||
|
|
166
|
+
(event.type === 'content_block_start' && event.content_block?.type === 'tool_use'))
|
|
167
|
+
throw refusal('SMOKE_NATIVE_UNEXPECTED_WORK');
|
|
168
|
+
};
|
|
169
|
+
const onAbort = () => {
|
|
170
|
+
void reader.cancel().catch(() => { });
|
|
171
|
+
};
|
|
172
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
173
|
+
try {
|
|
174
|
+
while (true) {
|
|
175
|
+
if (signal.aborted)
|
|
176
|
+
throw signal.reason || refusal('SMOKE_ABORTED');
|
|
177
|
+
const chunk = await reader.read();
|
|
178
|
+
if (chunk.done)
|
|
179
|
+
break;
|
|
180
|
+
if (chunk.value.byteLength === 0)
|
|
181
|
+
continue;
|
|
182
|
+
if (firstByteMs === null)
|
|
183
|
+
firstByteMs = now() - started;
|
|
184
|
+
bytes += chunk.value.byteLength;
|
|
185
|
+
if (bytes > LIMITS.maxResponseBytes)
|
|
186
|
+
throw refusal('SMOKE_RESPONSE_BOUND');
|
|
187
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
188
|
+
let match;
|
|
189
|
+
while ((match = /\r?\n\r?\n/.exec(buffer))) {
|
|
190
|
+
consume(buffer.slice(0, match.index));
|
|
191
|
+
buffer = buffer.slice(match.index + match[0].length);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (signal.aborted)
|
|
195
|
+
throw signal.reason || refusal('SMOKE_ABORTED');
|
|
196
|
+
if (buffer.trim())
|
|
197
|
+
consume(buffer);
|
|
198
|
+
if (!stopped ||
|
|
199
|
+
!['end_turn', 'max_tokens'].includes(stopReason || '') ||
|
|
200
|
+
!responseId ||
|
|
201
|
+
!/^msg[-_A-Za-z0-9:.]{1,188}$/.test(responseId) ||
|
|
202
|
+
!/^(?:anthropic\/)?claude-haiku-4-5(?:-20251001)?$/.test(reportedModel || ''))
|
|
203
|
+
throw refusal('SMOKE_NATIVE_INCOMPLETE');
|
|
204
|
+
return {
|
|
205
|
+
tokens: checkedUsage({ input_tokens: input, output_tokens: output }),
|
|
206
|
+
responseId,
|
|
207
|
+
reportedModel,
|
|
208
|
+
firstByteMs,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const failure = error instanceof Error ? error : refusal("SMOKE_NATIVE_STREAM_INVALID");
|
|
213
|
+
Object.assign(failure, { observed: {
|
|
214
|
+
input: integer(input) ? input : null,
|
|
215
|
+
output: integer(output) ? output : null,
|
|
216
|
+
responseId,
|
|
217
|
+
reportedModel,
|
|
218
|
+
firstByteMs,
|
|
219
|
+
} });
|
|
220
|
+
throw failure;
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
signal.removeEventListener('abort', onAbort);
|
|
224
|
+
await reader.cancel().catch(() => { });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export async function boundedOverloadSmokeResponse(response, signal) {
|
|
228
|
+
const reader = response.body?.getReader();
|
|
229
|
+
if (!reader)
|
|
230
|
+
throw refusal('SMOKE_RESPONSE_MISSING');
|
|
231
|
+
const chunks = [];
|
|
232
|
+
let size = 0;
|
|
233
|
+
const abort = () => {
|
|
234
|
+
void reader.cancel().catch(() => { });
|
|
235
|
+
};
|
|
236
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
237
|
+
try {
|
|
238
|
+
while (true) {
|
|
239
|
+
if (signal.aborted)
|
|
240
|
+
throw signal.reason || refusal('SMOKE_ABORTED');
|
|
241
|
+
const { value, done } = await reader.read();
|
|
242
|
+
if (done)
|
|
243
|
+
break;
|
|
244
|
+
size += value.byteLength;
|
|
245
|
+
if (size > LIMITS.maxResponseBytes)
|
|
246
|
+
throw refusal('SMOKE_RESPONSE_BOUND');
|
|
247
|
+
chunks.push(Buffer.from(value));
|
|
248
|
+
}
|
|
249
|
+
if (signal.aborted)
|
|
250
|
+
throw signal.reason || refusal('SMOKE_ABORTED');
|
|
251
|
+
return new Response(new Uint8Array(Buffer.concat(chunks)), {
|
|
252
|
+
status: response.status,
|
|
253
|
+
statusText: response.statusText,
|
|
254
|
+
headers: response.headers,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
signal.removeEventListener('abort', abort);
|
|
259
|
+
await reader.cancel().catch(() => { });
|
|
260
|
+
}
|
|
261
|
+
}
|