feat(models): freeze provider request contracts and observe actual headers
This commit is contained in:
@@ -9,6 +9,7 @@ import { modelEndpoint } from './model-hub.mjs';
|
||||
import { MODEL_PROTOCOLS } from '../../shared/contracts/model-capabilities.mjs';
|
||||
import { messagesAuthSettings, validateProtocolEndpoint } from '../../shared/contracts/model-endpoint.mjs';
|
||||
import { nativeParameterSettings } from '../../shared/contracts/native-parameters.mjs';
|
||||
import { effectiveRequestContract } from '../../shared/contracts/model-request-contract.mjs';
|
||||
|
||||
const digest = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
||||
export class ConfigImporter {
|
||||
@@ -35,6 +36,7 @@ export class ConfigImporter {
|
||||
...(item.nativeParameters !== undefined ? { nativeParameters: item.nativeParameters } : {}),
|
||||
...(item.outputTokenField !== undefined ? { outputTokenField: item.outputTokenField } : {}),
|
||||
...(item.parameterProfile !== undefined ? { parameterProfile: item.parameterProfile } : {}),
|
||||
requestContract: effectiveRequestContract(item),
|
||||
...(item.protocol === 'anthropic-messages' ? { messagesAuth: item.messagesAuth ?? 'api-key' } : {}),
|
||||
...(item.contextLimit !== undefined ? { contextLimit: item.contextLimit } : {}),
|
||||
...(item.maxOutputTokens !== undefined ? { maxOutputTokens: item.maxOutputTokens } : {}),
|
||||
|
||||
@@ -4,6 +4,7 @@ import { canonicalHost } from '../../shared/contracts/desktop-host.mjs';
|
||||
import { observeWindowsProcess } from '../desktop/process-identity.mjs';
|
||||
import { assertLocalTree } from '../desktop/file-state.mjs';
|
||||
import { protectCredential, unprotectCredential, credentialError } from '../desktop/windows-dpapi.mjs';
|
||||
import { requestCredentialIdentity } from '../../shared/contracts/model-request-contract.mjs';
|
||||
|
||||
const metadata = 'modelCredentials';
|
||||
const sha = value => createHash('sha256').update(value).digest('hex');
|
||||
@@ -24,7 +25,8 @@ export class CredentialVault {
|
||||
return sha(JSON.stringify(canonicalHost({ app: 'agent-workbench', scope: 'Windows.CurrentUser', userSid: this.userSid,
|
||||
dataIdentity: this.dataIdentity, connectionId: connection.id, connectionRevision: connection.credentialBindingRevision ?? connection.revision,
|
||||
protocol: connection.protocol, baseUrl: connection.baseUrl, model: connection.model, requiresKey: connection.requiresKey,
|
||||
...(connection.protocol === 'anthropic-messages' ? { messagesAuth: connection.messagesAuth ?? 'api-key' } : {}) })));
|
||||
...(connection.protocol === 'anthropic-messages' ? { messagesAuth: connection.messagesAuth ?? 'api-key' } : {}),
|
||||
...(requestCredentialIdentity(connection) ? { requestCredentialIdentity: requestCredentialIdentity(connection) } : {}) })));
|
||||
}
|
||||
status(connection) {
|
||||
if (connection.credentialSource) return { status: 'reference', storage: 'source-reference', sourceId: connection.credentialSource.connectionId,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { messagesAuthSettings, validateProtocolEndpoint } from '../../shared/con
|
||||
import { modelProtocol, capabilityDeclarations } from '../../shared/contracts/model-capabilities.mjs';
|
||||
import { DEFAULT_MODEL_CAPACITY } from '../../shared/contracts/model-capacity.mjs';
|
||||
import { resolveModelSpecification } from '../../shared/contracts/official-model-registry.mjs';
|
||||
import { requestCredentialIdentity, requestContractSettings, defaultMessagesAuth, requestCatalogBinding } from '../../shared/contracts/model-request-contract.mjs';
|
||||
|
||||
const fail = (message, status = 400) => Object.assign(new Error(message), { status });
|
||||
const stamp = () => new Date().toISOString();
|
||||
@@ -12,6 +13,7 @@ const clean = (value, max) => String(value ?? '').trim().slice(0, max);
|
||||
export const credentialScope = connection => createHash('sha256').update(JSON.stringify([
|
||||
connection.protocol ?? 'chat-completions', connection.baseUrl, connection.requiresKey !== false,
|
||||
connection.protocol === 'anthropic-messages' ? connection.messagesAuth ?? 'api-key' : null,
|
||||
...(requestCredentialIdentity(connection) ? [requestCredentialIdentity(connection)] : []),
|
||||
])).digest('hex');
|
||||
|
||||
export class ModelCatalog {
|
||||
@@ -59,8 +61,9 @@ export class ModelCatalog {
|
||||
const baseUrl = validateProtocolEndpoint(protocol, new URL(this.hub.provider.validate({ baseUrl: draft.baseUrl, mode: 'demo' })).toString().replace(/\/+$/, ''));
|
||||
if (baseUrl.length > 1000 || !clean(draft.name, 100)) throw fail('请先填写连接名称和接口根地址。');
|
||||
connection = { name: clean(draft.name, 100), brand: clean(draft.brand || '自定义', 40), baseUrl, protocol,
|
||||
...messagesAuthSettings(protocol, draft.messagesAuth), requiresKey: draft.requiresKey !== false, enabled: true,
|
||||
...messagesAuthSettings(protocol, defaultMessagesAuth({ ...draft, baseUrl }, { existing: false })), requiresKey: draft.requiresKey !== false, enabled: true,
|
||||
contextLimit: draft.contextLimit, maxOutputTokens: draft.maxOutputTokens, concurrency: draft.concurrency };
|
||||
connection.requestContract = requestContractSettings(draft.requestContract, connection, { existing: false });
|
||||
key = input.apiKey ?? '';
|
||||
if (typeof key !== 'string' || key.length > 16000) throw fail('模型凭据格式无效。');
|
||||
key = key.trim(); explicitKey = key || null;
|
||||
@@ -75,7 +78,7 @@ export class ModelCatalog {
|
||||
controller.signal.throwIfAborted();
|
||||
this.current({ binding });
|
||||
if (!unrestricted(this.hub.store) && (Date.now() >= deadline)) throw fail('获取模型目录超过60秒,请稍后重试。');
|
||||
const query = cursor ? '?' + cursorParameter + '=' + encodeURIComponent(cursor) + (cursorParameter === 'after_id' ? '&limit=100' : '') : connection.protocol === 'anthropic-messages' ? '?limit=100' : '';
|
||||
const query = cursor ? (route.includes('?') ? '&' : '?') + cursorParameter + '=' + encodeURIComponent(cursor) + (cursorParameter === 'after_id' ? '&limit=100' : '') : connection.protocol === 'anthropic-messages' ? (route.includes('?') ? '&' : '?') + 'limit=100' : '';
|
||||
const raw = await this.hub.provider.request({ ...this.hub.store.config, ...connection, model: '', mode: 'demo' }, route + query, undefined, controller.signal, key, undefined,
|
||||
{ attempts: 1, timeoutMs: unrestricted(this.hub.store) ? 0 : Math.min(20000, deadline - Date.now()), totalTimeoutMs: unrestricted(this.hub.store) ? 0 : Math.min(20000, deadline - Date.now()) });
|
||||
const encoded = this.hub.provider.redact(JSON.stringify(raw), key); bytes += Buffer.byteLength(encoded);
|
||||
@@ -99,7 +102,7 @@ export class ModelCatalog {
|
||||
if (!unrestricted(this.hub.store) && this.previews.size >= 8) this.previews.delete(this.previews.keys().next().value);
|
||||
const fetchedAt = stamp(), expires = Date.now() + 5 * 60000;
|
||||
const preview = { id, entries: [...entries.values()], fetchedAt, expiresAt: new Date(expires).toISOString(), complete, warning,
|
||||
source: { name: connection.name, baseUrl: connection.baseUrl, protocol: connection.protocol }, limits: unrestricted(this.hub.store) ? { connections: null, poolMembers: null, catalog: null } : { connections: 100, poolMembers: 32, catalog: 1000 } };
|
||||
source: { name: connection.name, baseUrl: connection.baseUrl, protocol: connection.protocol, ...(connection.requestContract ? { requestContract: structuredClone(connection.requestContract) } : {}) }, limits: unrestricted(this.hub.store) ? { connections: null, poolMembers: null, catalog: null } : { connections: 100, poolMembers: 32, catalog: 1000 } };
|
||||
this.previews.set(id, { preview, connection, binding, explicitKey, expires });
|
||||
return preview;
|
||||
} finally { this.active.delete(id); }
|
||||
@@ -131,12 +134,14 @@ export class ModelCatalog {
|
||||
&& (connection.id === owner?.id || connection.credentialSource?.connectionId === owner?.id));
|
||||
const upstreamModel = structuredClone({ ...model, fetchedAt: value.preview.fetchedAt, endpoint: value.connection.baseUrl });
|
||||
if (prior) {
|
||||
upstreamModel.requestBinding = { contract: requestCatalogBinding(value.connection), credentialRevision: hub.credential(owner)?.revision ?? 0 };
|
||||
prior.upstreamModel = upstreamModel;
|
||||
hub.save(); ids.push(prior.id); existing.push(prior.id); continue;
|
||||
}
|
||||
const reference = resolveModelSpecification({ ...value.connection, model: model.id, upstreamModel });
|
||||
const profile = hub.upsert({ name: value.connection.name + ' · ' + model.id, model: model.id,
|
||||
protocol: value.connection.protocol, baseUrl: value.connection.baseUrl, brand: value.connection.brand, messagesAuth: value.connection.messagesAuth,
|
||||
...(value.connection.requestContract ? { requestContract: structuredClone(value.connection.requestContract) } : {}),
|
||||
requiresKey: value.connection.requiresKey, concurrency: value.connection.concurrency, parameterProfile: value.connection.parameterProfile ?? 'auto',
|
||||
capabilityDeclarations: Object.fromEntries(Object.entries(model.capabilityDeclarations).map(([key, state]) => [key, state === 'unknown' ? declarations[key] : state])), streaming: false,
|
||||
capabilityDeclarationSources: Object.fromEntries(Object.entries(model.capabilityDeclarations).map(([key, state]) => [key, state !== 'unknown' ? 'upstream_catalog' : declarations[key] !== 'unknown' ? 'user' : 'protocol'])),
|
||||
@@ -146,6 +151,7 @@ export class ModelCatalog {
|
||||
const connection = hub.connection(profile.id); connection.upstreamModel = upstreamModel; connection.source = 'upstream-catalog';
|
||||
if (!owner) owner = connection;
|
||||
else connection.credentialSource = { connectionId: owner.id, scope: credentialScope(owner) };
|
||||
upstreamModel.requestBinding = { contract: requestCatalogBinding(value.connection), credentialRevision: hub.credential(owner)?.revision ?? 0 };
|
||||
hub.save(); ids.push(connection.id); added.push(connection.id);
|
||||
}
|
||||
let selection = null;
|
||||
|
||||
@@ -18,6 +18,7 @@ import { ModelCatalog, credentialScope } from './model-catalog.mjs';
|
||||
import { capacitySettings, routedCapacity } from '../../shared/contracts/model-capacity.mjs';
|
||||
import { ModelRequestLedger } from './request-ledger.mjs';
|
||||
import { modelOverrideSettings, resolveModelSpecification } from '../../shared/contracts/official-model-registry.mjs';
|
||||
import { defaultMessagesAuth, effectiveRequestContract, requestContractSettings, requestCredentialIdentity } from '../../shared/contracts/model-request-contract.mjs';
|
||||
|
||||
const legacyId = 'legacy-default';
|
||||
const stamp = () => new Date().toISOString();
|
||||
@@ -25,7 +26,8 @@ const error = (message, status = 400) => Object.assign(new Error(message), { sta
|
||||
const bounded = (value, fallback, min, max) => Number.isFinite(Number(value)) ? Math.max(min, Math.min(max, Math.trunc(Number(value)))) : fallback;
|
||||
const label = (value, maximum = 100) => String(value ?? '').trim().slice(0, maximum);
|
||||
const credentialProfile = connection => JSON.stringify([connection.protocol, connection.baseUrl, connection.model, connection.requiresKey,
|
||||
connection.protocol === 'anthropic-messages' ? connection.messagesAuth ?? 'api-key' : null]);
|
||||
connection.protocol === 'anthropic-messages' ? connection.messagesAuth ?? 'api-key' : null,
|
||||
...(requestCredentialIdentity(connection) ? [requestCredentialIdentity(connection)] : [])]);
|
||||
function declarationSources(input, previous, declarations) {
|
||||
const provided = input.capabilityDeclarationSources;
|
||||
if (provided !== undefined && (!provided || typeof provided !== 'object' || Array.isArray(provided)
|
||||
@@ -168,7 +170,7 @@ export class ModelHub {
|
||||
const credential = this.credential(connection), health = this.health.get(this.identity(connection));
|
||||
const capabilityEvidence = this.state.capabilityResults?.[connection.id];
|
||||
const ready = connection.enabled && (!connection.credentialSource || !!this.credentialOwner(connection)) && (!connection.requiresKey || !!credential?.key);
|
||||
return { ...connection, hasKey: !!credential?.key, credentialRevision: credential?.revision ?? 0, credentialStorage: 'memory',
|
||||
return { ...connection, requestContract: effectiveRequestContract(connection), hasKey: !!credential?.key, credentialRevision: credential?.revision ?? 0, credentialStorage: 'memory',
|
||||
...(this.credentialVault ? { savedCredential: this.credentialVault.status(connection) } : {}),
|
||||
status: !connection.enabled ? 'disabled' : !ready ? 'needs_key' : health?.blocked ? 'needs_attention' : health?.cooldownUntil > Date.now() ? 'cooling' : 'configured',
|
||||
activeRequests: this.leases.get(connection.id) ?? 0, health: health ?? { state: 'unverified' },
|
||||
@@ -258,12 +260,13 @@ export class ModelHub {
|
||||
if (!name || !model) throw error('请填写连接名称和实际模型名称。');
|
||||
const connection = { id: previous?.id ?? randomUUID(), name, brand: label(input.brand || '自定义', ceiling(this.store, 40)), protocol, model,
|
||||
capabilitySchema: 1, capabilityDeclarations: declarations, capabilityDeclarationSources, ...specificationSettings, streaming, ...(native ?? {}), ...modelIdentitySettings(input, previous ?? {}),
|
||||
...messagesAuthSettings(protocol, input.messagesAuth ?? previous?.messagesAuth),
|
||||
...messagesAuthSettings(protocol, input.messagesAuth ?? previous?.messagesAuth ?? defaultMessagesAuth({ baseUrl: input.baseUrl, protocol }, { existing: !!previous })),
|
||||
baseUrl: validateProtocolEndpoint(protocol, modelEndpoint(input.baseUrl)), enabled: input.enabled !== false, requiresKey: input.requiresKey !== false,
|
||||
...capacitySettings(input, previous ?? undefined, this.store.config),
|
||||
concurrency: unrestricted(this.store) ? (input.concurrency ?? 0) : bounded(input.concurrency, 1, 1, 8), revision: (previous?.revision ?? 0) + 1,
|
||||
source: previous?.source ?? 'manual', ...(previous?.importOrigin ? { importOrigin: previous.importOrigin, importRevision: previous.importRevision } : {}),
|
||||
createdAt: previous?.createdAt ?? stamp(), updatedAt: stamp() };
|
||||
connection.requestContract = requestContractSettings(input.requestContract, connection, { existing: !!previous, previous: previous ? effectiveRequestContract(previous) : null });
|
||||
// Keep an existing encrypted binding for edits that do not change its
|
||||
// endpoint/model/auth/key identity. Never decrypt or re-save the old key.
|
||||
connection.credentialBindingRevision = previous && !Object.hasOwn(input, 'apiKey') && credentialProfile(previous) === credentialProfile(connection)
|
||||
@@ -338,19 +341,23 @@ export class ModelHub {
|
||||
}
|
||||
prepare(config, selection = this.state.selected) {
|
||||
if (config.mode === 'demo') return config;
|
||||
if (selection.type === 'legacy' && !this.state.legacyConnection) return { ...config,
|
||||
modelSpecification: resolveModelSpecification({ ...config, capabilityDeclarationSources: { text: 'protocol', tools: 'protocol' } }), modelSpecificationFrozen: true };
|
||||
if (selection.type === 'legacy' && !this.state.legacyConnection) {
|
||||
const legacy = { ...config, requestContract: effectiveRequestContract(config), modelConnectionId: legacyId,
|
||||
modelConnectionRevision: config.configRevision ?? 1, modelCredentialRevision: this.provider.legacyCredentialRevision ?? 1 };
|
||||
return { ...legacy, modelSpecification: resolveModelSpecification({ ...legacy, capabilityDeclarationSources: { text: 'protocol', tools: 'protocol' } }), modelSpecificationFrozen: true };
|
||||
}
|
||||
if (this.catalog?.active.size) throw error('正在获取上游模型目录,请等待完成或取消。', 409);
|
||||
const pool = selection.type === 'pool' ? this.state.pools.find(value => value.id === selection.id) : null;
|
||||
if (selection.type === 'pool' && !pool) throw error('选中的模型池不存在。');
|
||||
const members = (pool?.members ?? [{ connectionId: selection.id, weight: 1 }]).map(value => {
|
||||
const connection = this.connection(value.connectionId), credentialRevision = this.credential(connection)?.revision ?? 0;
|
||||
const member = { ...connection, capabilityEvidence: this.state.capabilityResults?.[value.connectionId], weight: value.weight, credentialRevision,
|
||||
const member = { ...connection, requestContract: effectiveRequestContract(connection), capabilityEvidence: this.state.capabilityResults?.[value.connectionId], weight: value.weight, credentialRevision,
|
||||
...(connection.credentialSource ? { credentialSourceRevision: this.credentialOwner(connection)?.revision ?? null } : {}) };
|
||||
return { ...structuredClone(member), modelSpecification: resolveModelSpecification(member, credentialRevision), modelSpecificationFrozen: true };
|
||||
});
|
||||
if (!members.some(value => unrestricted(this.store) && value.enabled || this.status(value).status === 'configured' || this.status(value).status === 'cooling')) throw error('没有可用模型连接,请核对启用状态、临时凭据和故障。');
|
||||
return { ...config, ...messagesAuthSettings(members[0].protocol, members[0].messagesAuth), baseUrl: members[0].baseUrl, model: members[0].model, protocol: modelProtocol(members[0].protocol), streaming: members[0].streaming === true,
|
||||
requestContract: structuredClone(members[0].requestContract), modelConnectionRevision: members[0].revision,
|
||||
nativeParameters: members[0].nativeParameters ?? {}, outputTokenField: members[0].outputTokenField, parameterProfile: members[0].parameterProfile,
|
||||
modelSpecification: structuredClone(members[0].modelSpecification), modelSpecificationFrozen: true,
|
||||
modelConnectionId: members[0].id, modelCredentialRevision: members[0].credentialRevision,
|
||||
@@ -444,6 +451,7 @@ export class ModelHub {
|
||||
const progress = event => {
|
||||
if (event.modelIdentity) attempt.modelIdentity = event.modelIdentity;
|
||||
if (event.wireAttemptId) attempt.wireAttemptId = event.wireAttemptId;
|
||||
if (event.requestMetadata) { attempt.requestMetadata = event.requestMetadata; this.saveAttempts(attempt); }
|
||||
if (event.upstreamResponse) attempt.upstreamResponse = event.upstreamResponse;
|
||||
if (event.consumption) {
|
||||
if (event.consumption.modelIdentity) attempt.modelIdentity = event.consumption.modelIdentity;
|
||||
@@ -477,6 +485,7 @@ export class ModelHub {
|
||||
onProgress?.({ ...event, attempt: count, maxAttempts: routing.maxAttempts, connectionId: member.id, connectionName: member.name, protocol: modelProtocol(member.protocol), model: member.model, modelAttemptId: attempt.id });
|
||||
};
|
||||
const result = await execute({ ...config, ...modelIdentitySettings(member), ...messagesAuthSettings(member.protocol, member.messagesAuth), baseUrl: member.baseUrl, model: member.model, protocol: modelProtocol(member.protocol), streaming: member.streaming === true,
|
||||
requestContract: structuredClone(member.requestContract ?? effectiveRequestContract(member)), modelConnectionRevision: member.revision,
|
||||
modelConnectionId: member.id, modelCredentialRevision: member.credentialRevision }, credential?.key ?? '', actualBody, progress);
|
||||
attempt.status = 'completed'; attempt.usage = result.usage ?? attempt.usage; attempt.usageStatus = attempt.usage ? 'reported' : 'unknown';
|
||||
if (result.compatibility?.length) attempt.compatibility = result.compatibility;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { effectiveRequestContract, requestHeaders, credentialHeader } from '../../shared/contracts/model-request-contract.mjs';
|
||||
import { modelRequestUrl } from '../../shared/contracts/model-endpoint.mjs';
|
||||
const canonical = value => Array.isArray(value) ? value.map(canonical) : value && typeof value === 'object'
|
||||
? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value;
|
||||
const sha = value => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(canonical(value))).digest('hex');
|
||||
const promptFields = new Set(['model', 'tools', 'system', 'messages', 'input']);
|
||||
// Redact string values before serialization. A credential containing JSON
|
||||
// punctuation must never corrupt observation JSON or prevent an HTTP request.
|
||||
const redactValues = (value, redact) => typeof value === 'string' ? redact(value)
|
||||
: Array.isArray(value) ? value.map(item => redactValues(item, redact))
|
||||
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([name, item]) => [name, redactValues(item, redact)])) : value;
|
||||
export function preparedRequestMetadata(connection, body, { headers = requestHeaders(connection, '{{credential}}'), requestUrl = modelRequestUrl(connection), redact = String, wireBody } = {}) {
|
||||
const contract = effectiveRequestContract(connection);
|
||||
const templates = requestHeaders(connection, '{{credential}}');
|
||||
const observedHeaders = [...new Headers(headers)].map(([name, value]) => {
|
||||
const template = templates.get(name);
|
||||
return [name, credentialHeader(name) || template?.includes('{{credential}}') ? template ?? '[credential]' : redact(value)];
|
||||
});
|
||||
const nonPrompt = body ? Object.fromEntries(Object.entries(body).filter(([name]) => !promptFields.has(name))) : {};
|
||||
const nonPromptParameters = redactValues(nonPrompt, redact);
|
||||
const identity = { connectionId: connection.modelConnectionId ?? connection.id ?? null,
|
||||
connectionRevision: connection.revision ?? connection.modelConnectionRevision ?? null,
|
||||
credentialRevision: connection.modelCredentialRevision ?? connection.credentialRevision ?? null };
|
||||
const metadata = { schemaVersion: 1, representation: 'fetch-request-metadata-redacted-v1', method: body ? 'POST' : 'GET',
|
||||
protocol: connection.protocol ?? 'chat-completions', model: body?.model ?? connection.model ?? null, requestUrl: redact(requestUrl),
|
||||
headers: observedHeaders, identity, contract: redactValues(contract, redact),
|
||||
bodySha256: body ? sha(wireBody ?? JSON.stringify(body)) : null,
|
||||
nonPromptParameters, nonPromptSha256: sha(nonPromptParameters), source: 'prepared-fetch-arguments', upstreamCache: 'unknown' };
|
||||
metadata.fingerprint = sha({ method: metadata.method, protocol: metadata.protocol, model: metadata.model, requestUrl: metadata.requestUrl,
|
||||
headers: metadata.headers, identity, nonPromptParameters });
|
||||
metadata.fingerprintMethod = 'canonical-json-sha256-without-prompt-or-credential-values-v1';
|
||||
return metadata;
|
||||
}
|
||||
export function requestContractAudit(body, config, previousBody = null, previousConfig = null) {
|
||||
const variants = input => input.kind === 'model-route-plan' ? input.variants : [{ connectionId: null, body: input }];
|
||||
const entries = (input, settings) => variants(input).map(variant => {
|
||||
const member = settings.modelRouting?.members?.find(value => value.id === variant.connectionId) ?? settings;
|
||||
return { connectionId: variant.connectionId, ...preparedRequestMetadata(member, variant.body),
|
||||
representation: 'frozen-request-contract-redacted-v1', source: 'frozen-run-contract' };
|
||||
});
|
||||
const prior = previousBody && previousConfig ? entries(previousBody, previousConfig) : [];
|
||||
return { schemaVersion: 1, method: 'frozen-request-contract-observation-v1', upstreamCache: 'unknown', variants: entries(body, config).map(entry => {
|
||||
const old = prior.find(value => value.connectionId === entry.connectionId && value.protocol === entry.protocol);
|
||||
return { ...entry, previousFingerprint: old?.fingerprint ?? null, reason: !old ? 'first_or_new_route' : old.fingerprint === entry.fingerprint ? 'same_observed_contract' : 'observed_contract_changed',
|
||||
changed: old ? ['model', 'requestUrl', 'headers', 'identity', 'nonPromptParameters'].filter(field => JSON.stringify(canonical(old[field])) !== JSON.stringify(canonical(entry[field]))) : [] };
|
||||
}) };
|
||||
}
|
||||
@@ -4,7 +4,8 @@ export const ERROR_CAPTURE_LIMIT = 64 * 1024;
|
||||
const PREVIEW_LIMIT = 8000;
|
||||
const allowedHeaders = ['content-type', 'retry-after', 'date', 'x-request-id', 'request-id', 'requestid', 'x-amzn-requestid',
|
||||
'anthropic-request-id', 'x-ratelimit-limit-requests', 'x-ratelimit-remaining-requests', 'x-ratelimit-reset-requests',
|
||||
'x-ratelimit-limit-tokens', 'x-ratelimit-remaining-tokens', 'x-ratelimit-reset-tokens'];
|
||||
'x-ratelimit-limit-tokens', 'x-ratelimit-remaining-tokens', 'x-ratelimit-reset-tokens', 'openai-version', 'openai-organization', 'openai-project', 'openai-processing-ms',
|
||||
'x-ratelimit-limit-project-tokens', 'x-ratelimit-remaining-project-tokens', 'x-ratelimit-reset-project-tokens', 'anthropic-version', 'anthropic-workspace-id'];
|
||||
|
||||
export function sanitizeModelText(value, redact = String) {
|
||||
return redact(String(value))
|
||||
|
||||
Reference in New Issue
Block a user