dsh-model-think-level 1.1.8 → 2.0.2
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/LICENSE +13 -0
- package/README.md +38 -0
- package/assets/NOTICE.md +15 -0
- package/assets/unified_bank.json +32910 -0
- package/lib/client/ComposerSlider.d.ts +9 -9
- package/lib/client/EffortEditor.d.ts +22 -12
- package/lib/client/FingerprintPane.d.ts +36 -0
- package/lib/client/KeyManager.d.ts +36 -10
- package/lib/client/ProtocolMenu.d.ts +51 -0
- package/lib/client/capacity.d.ts +30 -0
- package/lib/client/events.d.ts +26 -0
- package/lib/client/fingerprint-client.d.ts +81 -0
- package/lib/client/fingerprint-runner.d.ts +61 -0
- package/lib/client/index.d.ts +6 -0
- package/lib/client/injection/add-card.d.ts +4 -0
- package/lib/client/injection/create-card-pane.d.ts +15 -0
- package/lib/client/injection/create-key-seat.d.ts +53 -0
- package/lib/client/injection/create-keys-pane.d.ts +46 -0
- package/lib/client/injection/editor-tab-bar.d.ts +2 -1
- package/lib/client/injection/editor-tabs.d.ts +11 -1
- package/lib/client/injection/key-reveal.d.ts +24 -0
- package/lib/client/injection/models-page-editor.d.ts +165 -1
- package/lib/client/injection/provider-card-slot.d.ts +3 -1
- package/lib/client/injection/provider-endpoints.d.ts +70 -0
- package/lib/client/injection/staged-keys.d.ts +169 -0
- package/lib/client/key-manager-client.d.ts +89 -12
- package/lib/client/locales.d.ts +80 -6
- package/lib/client/ops.d.ts +4 -0
- package/lib/client/refresh-scheduler.d.ts +29 -0
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/types.d.ts +44 -2
- package/lib/client.js +2275 -266
- package/lib/client.js.map +4 -4
- package/lib/constants.d.ts +11 -0
- package/lib/discovery-merge.d.ts +35 -0
- package/lib/fingerprint/bank.d.ts +24 -0
- package/lib/fingerprint/challenges.d.ts +14 -0
- package/lib/fingerprint/core.d.ts +85 -0
- package/lib/fingerprint/eligibility.d.ts +8 -0
- package/lib/fingerprint/random.d.ts +4 -0
- package/lib/fingerprint/run.d.ts +110 -0
- package/lib/fingerprint/store.d.ts +31 -0
- package/lib/fingerprint/verdict.d.ts +64 -0
- package/lib/headers-fetch.d.ts +53 -3
- package/lib/headers-pi-ai.d.ts +31 -1
- package/lib/index.d.ts +3 -19
- package/lib/index.js +2438 -153
- package/lib/index.js.map +4 -4
- package/lib/key-index.d.ts +58 -1
- package/lib/key-probe.d.ts +126 -0
- package/lib/key-refs.d.ts +106 -0
- package/lib/key-route-core.d.ts +415 -0
- package/lib/knowledge.d.ts +6 -5
- package/lib/listing.d.ts +118 -0
- package/lib/multi-key-listing.d.ts +101 -0
- package/package.json +13 -5
package/lib/constants.d.ts
CHANGED
|
@@ -57,6 +57,17 @@ export declare const AUTOFILL_CONFIG_PATH = "/dsh-model-think-level/autofill-con
|
|
|
57
57
|
* cannot observe it on its own.
|
|
58
58
|
*/
|
|
59
59
|
export declare const HEADERS_CONFIG_PATH = "/dsh-model-think-level/headers-config";
|
|
60
|
+
/**
|
|
61
|
+
* Same-origin host route owning model fingerprint attribution (ModelTrace).
|
|
62
|
+
*
|
|
63
|
+
* Three verbs on one path: `GET` returns the stored records for one provider
|
|
64
|
+
* plus the bank summary the page needs to label families; `POST` runs one
|
|
65
|
+
* model's three challenges and stores the verdict; `DELETE` forgets one model.
|
|
66
|
+
* The attribution itself is `src/fingerprint/`, a pure port of ModelTrace's
|
|
67
|
+
* `fingerprint-core.js` over a vendored bank -- so this route only does the
|
|
68
|
+
* plumbing: run challenges through the llm service, parse, store.
|
|
69
|
+
*/
|
|
70
|
+
export declare const FINGERPRINT_PATH = "/dsh-model-think-level/fingerprint";
|
|
60
71
|
/** The settings namespace this plugin edits: pi-ai custom provider routes. */
|
|
61
72
|
export declare const PI_AI_NS = "llm-pi-ai";
|
|
62
73
|
/**
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One provider listing probe: ask an endpoint for the models it advertises.
|
|
3
|
+
*
|
|
4
|
+
* The same discipline governs every place this plugin interrogates an endpoint
|
|
5
|
+
* — the probe route, the key panel's discover op, the per-key discovery pass
|
|
6
|
+
* and the fetch overlay's aggregated catalogue — so the one bounded, signed,
|
|
7
|
+
* redirect-refusing read lives here once: the profile's configured request
|
|
8
|
+
* headers ride along, the credential is signed the way the protocol expects, a
|
|
9
|
+
* listing is never a place to be forwarded, and the reply is bounded before it
|
|
10
|
+
* is parsed.
|
|
11
|
+
*
|
|
12
|
+
* @module dsh-model-think-level/discovery-merge
|
|
13
|
+
*/
|
|
14
|
+
import { type ListedModel } from './listing.js';
|
|
15
|
+
import type { RouteProtocol } from './key-refs.js';
|
|
16
|
+
/** One listing request: where to ask, and which credential to sign it with. */
|
|
17
|
+
export interface ListingProbe {
|
|
18
|
+
readonly baseURL: string;
|
|
19
|
+
readonly api: RouteProtocol;
|
|
20
|
+
readonly apiKey?: string | undefined;
|
|
21
|
+
readonly headers?: unknown;
|
|
22
|
+
readonly timeoutMs: number;
|
|
23
|
+
/** Transport override: the tests' stub, and the plugin's own fetch seam. */
|
|
24
|
+
readonly send?: (url: string, init: RequestInit) => Promise<Response>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ask one endpoint for the models it advertises.
|
|
28
|
+
*
|
|
29
|
+
* A probe that cannot be read — network, status, malformed body — answers
|
|
30
|
+
* undefined instead of throwing: a listing probe is always an enrichment,
|
|
31
|
+
* never a precondition of the caller's own work.
|
|
32
|
+
* @param probe - the endpoint, protocol, credential, and transport.
|
|
33
|
+
* @returns the listing's models, or undefined when it could not be read.
|
|
34
|
+
*/
|
|
35
|
+
export declare function probeListing(probe: ListingProbe): Promise<ListedModel[] | undefined>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Bank } from './core.js';
|
|
2
|
+
export interface BankModelSummary {
|
|
3
|
+
id: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
family: string;
|
|
6
|
+
familyName: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BankSummary {
|
|
9
|
+
builtAt: string;
|
|
10
|
+
schema: string;
|
|
11
|
+
models: BankModelSummary[];
|
|
12
|
+
families: Array<{
|
|
13
|
+
family: string;
|
|
14
|
+
name: string;
|
|
15
|
+
models: number;
|
|
16
|
+
}>;
|
|
17
|
+
recommendedQueries: number;
|
|
18
|
+
}
|
|
19
|
+
/** 只做形状校验并收窄成 `Bank`;不改任何数值。 */
|
|
20
|
+
export declare function parseBank(raw: unknown): Bank;
|
|
21
|
+
/** 同步读包内的指纹库。结果只解析一次。 */
|
|
22
|
+
export declare function loadBankSync(): Bank;
|
|
23
|
+
export declare function summarizeBank(bank: Bank): BankSummary;
|
|
24
|
+
export declare function bankBuiltAt(bank: Bank): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Challenge {
|
|
2
|
+
id: string;
|
|
3
|
+
expected_count: number;
|
|
4
|
+
prompt: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function generateChallenges(count?: number): Challenge[];
|
|
7
|
+
/** 三题应答的最小有效数字个数:`max(80, ceil(expected * 0.55))`。 */
|
|
8
|
+
export declare function minimumNumbers(expectedCount: number): number;
|
|
9
|
+
export declare const CHALLENGE_TEXT: {
|
|
10
|
+
readonly openings: string[];
|
|
11
|
+
readonly actions: string[];
|
|
12
|
+
readonly endings: string[];
|
|
13
|
+
readonly separatorHints: string[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export declare const VALUE_MIN = 1;
|
|
2
|
+
export declare const VALUE_MAX = 355;
|
|
3
|
+
export declare const DIMENSION: number;
|
|
4
|
+
export declare const ALPHA = 0.5;
|
|
5
|
+
export declare const ORDERED_BLOCK_WEIGHT = 0.25;
|
|
6
|
+
/** 银行里的一位候选模型。`counts` 与 `DIMENSION` 等长。 */
|
|
7
|
+
export interface BankModel {
|
|
8
|
+
id: string;
|
|
9
|
+
display_name: string;
|
|
10
|
+
family: string;
|
|
11
|
+
family_name?: string;
|
|
12
|
+
counts: number[];
|
|
13
|
+
}
|
|
14
|
+
export interface BankArtifact {
|
|
15
|
+
feature_mean: number[];
|
|
16
|
+
feature_scale: number[];
|
|
17
|
+
nuisance_basis: number[][];
|
|
18
|
+
centroids: number[][];
|
|
19
|
+
weight?: number;
|
|
20
|
+
environment_centroids?: number[][][];
|
|
21
|
+
}
|
|
22
|
+
export interface Bank {
|
|
23
|
+
schema?: string;
|
|
24
|
+
built_at?: string;
|
|
25
|
+
method?: string;
|
|
26
|
+
recommended_queries?: number;
|
|
27
|
+
minimum_valid_numbers?: number;
|
|
28
|
+
models: BankModel[];
|
|
29
|
+
robust: {
|
|
30
|
+
model_order?: string[];
|
|
31
|
+
hellinger: BankArtifact;
|
|
32
|
+
ordered_blocks: BankArtifact;
|
|
33
|
+
};
|
|
34
|
+
calibration: Record<string, {
|
|
35
|
+
beta: number;
|
|
36
|
+
cv_accuracy: number;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export interface Output {
|
|
40
|
+
text: string;
|
|
41
|
+
expected_count: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ResultRow {
|
|
44
|
+
model: string;
|
|
45
|
+
display_name: string;
|
|
46
|
+
probability: number;
|
|
47
|
+
profile_similarity: number;
|
|
48
|
+
score: number;
|
|
49
|
+
family: string;
|
|
50
|
+
family_name: string;
|
|
51
|
+
conditional_probability: number;
|
|
52
|
+
}
|
|
53
|
+
export interface Diagnostic {
|
|
54
|
+
index: number;
|
|
55
|
+
parsed_numbers: number;
|
|
56
|
+
minimum_numbers: number;
|
|
57
|
+
accepted: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface AttributionResult {
|
|
60
|
+
prediction: string;
|
|
61
|
+
prediction_name: string;
|
|
62
|
+
probability: number;
|
|
63
|
+
used_outputs: number;
|
|
64
|
+
results: ResultRow[];
|
|
65
|
+
diagnostics: Diagnostic[];
|
|
66
|
+
calibration: {
|
|
67
|
+
queries: number;
|
|
68
|
+
beta: number;
|
|
69
|
+
cv_accuracy: number;
|
|
70
|
+
};
|
|
71
|
+
family_prediction: string;
|
|
72
|
+
family_prediction_name: string;
|
|
73
|
+
family_probability: number;
|
|
74
|
+
family_probabilities: Array<{
|
|
75
|
+
family: string;
|
|
76
|
+
display_name: string;
|
|
77
|
+
probability: number;
|
|
78
|
+
}>;
|
|
79
|
+
method: string;
|
|
80
|
+
}
|
|
81
|
+
/** 三题全废时抛出,文案照抄上游,别改写。 */
|
|
82
|
+
export declare const NO_USABLE_OUTPUT = "\u6CA1\u6709\u53EF\u7528\u56DE\u7B54\uFF1A\u8BF7\u7C98\u8D34\u5B8C\u6574\u6570\u5B57\u5E8F\u5217\uFF1B\u62D2\u7B54\u6216\u4E25\u91CD\u622A\u65AD\u7684\u56DE\u7B54\u4E0D\u4F1A\u8BA1\u5165\u3002";
|
|
83
|
+
export declare function parseNumbers(text: string): number[];
|
|
84
|
+
export declare function countNumbers(numbers: number[]): number[];
|
|
85
|
+
export declare function analyzeGlobalOutputs(outputs: Output[], bank: Bank): AttributionResult;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** 取模型 id 里最后一个 `/` 之后的部分,兼容 `anthropic/claude-…` 这类带前缀的写法。 */
|
|
2
|
+
export declare function bareModelId(modelId: string): string;
|
|
3
|
+
/** 该模型是否能被当前指纹库判定。 */
|
|
4
|
+
export declare function isEligibleModel(modelId: string): boolean;
|
|
5
|
+
/** 从一串模型 id 里挑出可检测的那几个,保持原顺序。 */
|
|
6
|
+
export declare function eligibleModels<T extends string>(modelIds: readonly T[]): T[];
|
|
7
|
+
/** 面向用户的家族名,用于文案(「GPT 系列」/「Claude 系列」)。 */
|
|
8
|
+
export declare function familyLabelOf(modelId: string): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One fingerprint probe: ask one model one challenge, keep its visible answer.
|
|
3
|
+
*
|
|
4
|
+
* This is the only module that touches the harness `llm` service. Everything
|
|
5
|
+
* else in `src/fingerprint/` is pure or filesystem-only, so the whole
|
|
6
|
+
* attribution math stays testable without a live provider.
|
|
7
|
+
*
|
|
8
|
+
* The request shape is deliberately ModelTrace's: one bare user message, no
|
|
9
|
+
* system prompt, no tools. Two deviations are worth naming.
|
|
10
|
+
*
|
|
11
|
+
* - `reasoningEffort` is LEFT UNSET on purpose. ModelTrace calls a plain chat
|
|
12
|
+
* completion, so the measured behaviour is the model under its own default.
|
|
13
|
+
* Setting an explicit effort would ask a *different* model behaviour than the
|
|
14
|
+
* one the fingerprint bank was built from, and the wire vocabulary for "off"
|
|
15
|
+
* differs per provider (`none`, `minimal`, `null`, or a 400). The plugin's
|
|
16
|
+
* own default-guard may still materialize one, exactly as it would for a
|
|
17
|
+
* normal user message -- so the probe measures the model under the plugin's
|
|
18
|
+
* normal conditions.
|
|
19
|
+
* - Only `text-delta` chunks are collected. `reasoning-delta` is thinking, not
|
|
20
|
+
* the answer the challenge asks for, and feeding it to {@link parseNumbers}
|
|
21
|
+
* would pollute the distribution with whatever the model happened to reason
|
|
22
|
+
* about.
|
|
23
|
+
*
|
|
24
|
+
* @module dsh-model-think-level/fingerprint/run
|
|
25
|
+
*/
|
|
26
|
+
import type { Output } from './core.js';
|
|
27
|
+
/** The llm surface this probe drives: prepare, then dispatch once. */
|
|
28
|
+
export interface ProbeDispatch {
|
|
29
|
+
prepareCall(config: Record<string, unknown>, signal?: unknown): Promise<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Runtime-level dispatch, used only when a prepared call carries no dispatch
|
|
32
|
+
* of its own. The harness's `PreparedLlmCall` owns `.stream`, which is the
|
|
33
|
+
* preferred half because it is the one that already holds the prepared call's
|
|
34
|
+
* auth and routing.
|
|
35
|
+
*/
|
|
36
|
+
stream?(options: Record<string, unknown>): AsyncIterable<unknown>;
|
|
37
|
+
}
|
|
38
|
+
/** What one challenge produced, accepted or not. */
|
|
39
|
+
export interface ProbeOutcome {
|
|
40
|
+
/** Zero-based challenge index, matching `generateChallenges` order. */
|
|
41
|
+
index: number;
|
|
42
|
+
/** Challenge id, e.g. `probe-1-9f2c41a7b03d12`. */
|
|
43
|
+
challengeId: string;
|
|
44
|
+
/** How many integers the challenge asked for. */
|
|
45
|
+
expectedCount: number;
|
|
46
|
+
/** Whether a model call completed and produced any visible text. */
|
|
47
|
+
ok: boolean;
|
|
48
|
+
/** Visible answer text; empty when `ok` is false. */
|
|
49
|
+
text: string;
|
|
50
|
+
/** Failure description, present only when `ok` is false. */
|
|
51
|
+
error?: string;
|
|
52
|
+
/** Why the stream stopped, when one was reported. */
|
|
53
|
+
finish?: string;
|
|
54
|
+
}
|
|
55
|
+
/** Everything one model's fingerprint run learned, ready for the bank. */
|
|
56
|
+
export interface ProbeRunResult {
|
|
57
|
+
/** Per challenge, in order. */
|
|
58
|
+
outcomes: ProbeOutcome[];
|
|
59
|
+
/** The accepted subset, ready for `analyzeGlobalOutputs`. */
|
|
60
|
+
outputs: Output[];
|
|
61
|
+
}
|
|
62
|
+
/** One challenge to put to the model. */
|
|
63
|
+
export interface ProbeChallenge {
|
|
64
|
+
id: string;
|
|
65
|
+
expected_count: number;
|
|
66
|
+
prompt: string;
|
|
67
|
+
}
|
|
68
|
+
/** Options for {@link runProbe}. */
|
|
69
|
+
export interface RunProbeOptions {
|
|
70
|
+
/** Registered provider route selecting the adapter. */
|
|
71
|
+
provider: string;
|
|
72
|
+
/** Exact model id. */
|
|
73
|
+
model: string;
|
|
74
|
+
/** Challenges to run, in order. */
|
|
75
|
+
challenges: readonly ProbeChallenge[];
|
|
76
|
+
/** The harness llm service. */
|
|
77
|
+
llm: ProbeDispatch;
|
|
78
|
+
/** Caller cancellation; combined with the per-probe timeout. */
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
/** Per-challenge timeout in milliseconds. Defaults to 120000. */
|
|
81
|
+
timeoutMs?: number;
|
|
82
|
+
/** Sampling cap for one answer. Defaults to 4000. */
|
|
83
|
+
maxTokens?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Called as each challenge settles, so a caller can stream progress. Fire
|
|
86
|
+
* order is completion order, which for parallel runs is not `index` order.
|
|
87
|
+
*/
|
|
88
|
+
onOutcome?: (outcome: ProbeOutcome) => void;
|
|
89
|
+
}
|
|
90
|
+
/** Default per-challenge timeout: two minutes is generous for 300 integers. */
|
|
91
|
+
export declare const DEFAULT_PROBE_TIMEOUT_MS = 120000;
|
|
92
|
+
/**
|
|
93
|
+
* Enough room for 292-332 integers plus whatever preamble the model refuses to
|
|
94
|
+
* drop. Parsed-count tolerance (55% of expected) means a truncated answer can
|
|
95
|
+
* still score, but a full run is strictly better.
|
|
96
|
+
*/
|
|
97
|
+
export declare const DEFAULT_PROBE_MAX_TOKENS = 4000;
|
|
98
|
+
/**
|
|
99
|
+
* Ask one model one challenge and keep its visible answer.
|
|
100
|
+
*
|
|
101
|
+
* Never throws for a provider-side failure: a rejected or empty answer comes
|
|
102
|
+
* back as an outcome with `ok: false`, because one dead challenge must not
|
|
103
|
+
* discard the two that worked. Throws only for programmer errors (no
|
|
104
|
+
* challenges) and for an `AbortSignal` that the *caller* cancelled -- an abort
|
|
105
|
+
* is a decision, not a result.
|
|
106
|
+
*
|
|
107
|
+
* @param options - the run.
|
|
108
|
+
* @returns every outcome in order, plus the accepted subset.
|
|
109
|
+
*/
|
|
110
|
+
export declare function runProbe(options: RunProbeOptions): Promise<ProbeRunResult>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type FingerprintRecord, type FingerprintStatus, type FingerprintTopEntry } from './verdict.js';
|
|
2
|
+
export { type FingerprintRecord, type FingerprintStatus, type FingerprintTopEntry };
|
|
3
|
+
export interface FingerprintDocument {
|
|
4
|
+
version: 1;
|
|
5
|
+
/** 银行的 built_at;换银行就整体失效。 */
|
|
6
|
+
bankBuiltAt: string;
|
|
7
|
+
records: Record<string, FingerprintRecord>;
|
|
8
|
+
}
|
|
9
|
+
export declare function emptyFingerprintStore(bankBuiltAt?: string): FingerprintDocument;
|
|
10
|
+
/** 记录键。`\u0000` 在模型 id 与供应商 id 里都不可能出现。 */
|
|
11
|
+
export declare function recordKeyOf(provider: string, model: string): string;
|
|
12
|
+
export declare function fingerprintFilePath(home?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 解析已解码的文档。永远不抛错:银行换了、文件被手改坏、条目形状不对,
|
|
15
|
+
* 代价最多是那一条被丢掉,不会让用户丢掉全部历史。
|
|
16
|
+
* @param raw - 解码后的 JSON 值。
|
|
17
|
+
* @param bankBuiltAt - 当前指纹库的 built_at;对不上就整体视为无历史。
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseFingerprintStore(raw: unknown, bankBuiltAt?: string): FingerprintDocument;
|
|
20
|
+
/** 读结果库;只有文件不存在才返回空库。 */
|
|
21
|
+
export declare function readFingerprintStore(bankBuiltAt?: string, file?: string): FingerprintDocument;
|
|
22
|
+
/** 原子写库。 */
|
|
23
|
+
export declare function writeFingerprintStore(document: FingerprintDocument, file?: string): void;
|
|
24
|
+
/** 一次读-改-写。返回的就是落盘后的文档。 */
|
|
25
|
+
export declare function updateFingerprintStore(mutate: (document: FingerprintDocument) => FingerprintDocument, bankBuiltAt?: string, file?: string): FingerprintDocument;
|
|
26
|
+
/** 覆盖或新增一条记录。 */
|
|
27
|
+
export declare function withRecord(document: FingerprintDocument, record: FingerprintRecord): FingerprintDocument;
|
|
28
|
+
/** 删掉一条记录(供应商或模型被删掉时用)。 */
|
|
29
|
+
export declare function withoutRecord(document: FingerprintDocument, provider: string, model: string): FingerprintDocument;
|
|
30
|
+
/** 一个供应商下的全部记录。 */
|
|
31
|
+
export declare function providerRecords(document: FingerprintDocument, provider: string): FingerprintRecord[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AttributionResult, ResultRow } from './core.js';
|
|
2
|
+
/** 落盘的三种状态。`running` 不落盘,只活在客户端 runner 里。 */
|
|
3
|
+
export type FingerprintStatus = 'identified' | 'doubtful' | 'failed';
|
|
4
|
+
/** 结果卡「前三候选」里的一条。 */
|
|
5
|
+
export interface FingerprintTopEntry {
|
|
6
|
+
model: string;
|
|
7
|
+
probability: number;
|
|
8
|
+
similarity: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 一个模型的一次检测结论,也是落盘的那一行。
|
|
12
|
+
*
|
|
13
|
+
* 这个形状放在这里而不是 store 里,是因为**前端画徽章要用它**:store 是
|
|
14
|
+
* Node-only(`node:fs`),浏览器只能从纯模块取形状。判据、结果条目、结果行
|
|
15
|
+
* 三者属于同一件事的三个面,拆开会各长各的。
|
|
16
|
+
*/
|
|
17
|
+
export interface FingerprintRecord {
|
|
18
|
+
provider: string;
|
|
19
|
+
model: string;
|
|
20
|
+
status: FingerprintStatus;
|
|
21
|
+
checkedAt: number;
|
|
22
|
+
usedOutputs: number;
|
|
23
|
+
/** 仅 identified / doubtful 有值。 */
|
|
24
|
+
prediction?: string;
|
|
25
|
+
predictionName?: string;
|
|
26
|
+
probability?: number;
|
|
27
|
+
familyPrediction?: string;
|
|
28
|
+
familyProbability?: number;
|
|
29
|
+
top?: FingerprintTopEntry[];
|
|
30
|
+
calibration?: {
|
|
31
|
+
queries: number;
|
|
32
|
+
cvAccuracy: number;
|
|
33
|
+
};
|
|
34
|
+
/** 仅 failed 有值,面向用户的失败原因。 */
|
|
35
|
+
error?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `identified` 的概率下界。
|
|
39
|
+
*
|
|
40
|
+
* 库里 18 个候选的均匀先验是 5.6%,0.6 已经是压倒性的;低于它就说明几个候选
|
|
41
|
+
* 咬得很近,说「像」不负责任。
|
|
42
|
+
*/
|
|
43
|
+
export declare const IDENTIFIED_THRESHOLD = 0.6;
|
|
44
|
+
/** 出一个确定结论需要的完整题数。 */
|
|
45
|
+
export declare const FULL_RUN_QUERIES = 3;
|
|
46
|
+
/**
|
|
47
|
+
* 取概率最高的前几名候选,供结果卡画条形。
|
|
48
|
+
* @param rows - 已按概率降序排好的候选。
|
|
49
|
+
* @param limit - 取几名,默认 3。
|
|
50
|
+
* @returns 前 `limit` 条的模型 id、概率、相似度。
|
|
51
|
+
*/
|
|
52
|
+
export declare function topEntriesOf(rows: readonly ResultRow[], limit?: number): FingerprintTopEntry[];
|
|
53
|
+
/**
|
|
54
|
+
* 把一次归属结论定级。
|
|
55
|
+
*
|
|
56
|
+
* 两道闸:概率必须够高,而且三题必须都有效。1 题的交叉验证准确率只有
|
|
57
|
+
* 96.3%,不够撑一个确定结论 —— 所以有效题数不足一律降级为 `doubtful`,
|
|
58
|
+
* 哪怕那一题的概率是 0.99。
|
|
59
|
+
*
|
|
60
|
+
* @param attribution - `analyzeGlobalOutputs` 的结果;失败时传 null。
|
|
61
|
+
* @param usedOutputs - 有效题数。
|
|
62
|
+
* @returns 落盘与画徽章共用的状态。
|
|
63
|
+
*/
|
|
64
|
+
export declare function statusOf(attribution: AttributionResult | null, usedOutputs: number): FingerprintStatus;
|
package/lib/headers-fetch.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The fetch-layer installer for provider request-header overrides
|
|
3
|
-
* WHAT to
|
|
2
|
+
* The fetch-layer installer for provider request-header overrides AND multi-key
|
|
3
|
+
* request signing. The decision of WHAT to send lives in `headers-core.ts` (which
|
|
4
|
+
* headers a route declares) and `key-route-core.ts` (which key a route should
|
|
5
|
+
* sign with, and whether a failed attempt deserves the next key); this module
|
|
6
|
+
* owns the global seam and performs the retries.
|
|
4
7
|
*
|
|
5
8
|
* Shape of the seam: one process-wide wrapper owns `globalThis.fetch`, and
|
|
6
9
|
* every activation is an ENTRY inside it. That is what makes the plugin safe
|
|
@@ -23,9 +26,35 @@
|
|
|
23
26
|
* public surface that sees the merged headers. Both were probed against the
|
|
24
27
|
* real runtime — see `.tmp-rel/headers-probe/`.
|
|
25
28
|
*
|
|
29
|
+
* Why fetch is ALSO where multi-key failover lives: the provider pushes its
|
|
30
|
+
* `start` event only after a successful HTTP response and turns a bad key
|
|
31
|
+
* (401/403) or rate limit (429) into a thrown error, so by the time pi-ai sees
|
|
32
|
+
* a failure the request has already been spent. This wrapper holds the raw
|
|
33
|
+
* `Response` — status included — before the SDK interprets it, so it can cancel
|
|
34
|
+
* a rejected attempt and re-issue it with the next key while the request body
|
|
35
|
+
* is still available.
|
|
36
|
+
*
|
|
26
37
|
* @module dsh-model-think-level/headers-fetch
|
|
27
38
|
*/
|
|
28
39
|
import { emptyIndex, type HeaderIndex } from './headers-core.js';
|
|
40
|
+
import { type KeyCandidate } from './key-route-core.js';
|
|
41
|
+
/** What a key resolver is told about the request it must sign. */
|
|
42
|
+
export interface KeyRouteContext {
|
|
43
|
+
/** The provider route whose profile matched the request URL. */
|
|
44
|
+
readonly route: string;
|
|
45
|
+
/** The model id the request body named, when it could be read. */
|
|
46
|
+
readonly model: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
/** Context for aggregating a provider's model listing across its keys. */
|
|
49
|
+
export interface ModelListingContext {
|
|
50
|
+
readonly route: string;
|
|
51
|
+
readonly url: string;
|
|
52
|
+
readonly headers: Headers;
|
|
53
|
+
readonly keys: readonly KeyCandidate[];
|
|
54
|
+
readonly signal?: AbortSignal | null;
|
|
55
|
+
/** The fetch below this plugin's wrapper, avoiding recursive interception. */
|
|
56
|
+
readonly send: typeof globalThis.fetch;
|
|
57
|
+
}
|
|
29
58
|
/** Handle one activation keeps; `dispose` is idempotent. */
|
|
30
59
|
export interface HeaderOverlayHandle {
|
|
31
60
|
/** Remove this activation's entry, restoring the original fetch when it was the last. */
|
|
@@ -38,15 +67,36 @@ export interface HeaderOverlay extends HeaderOverlayHandle {
|
|
|
38
67
|
}
|
|
39
68
|
/** A mutable index source an activation reads on every request. */
|
|
40
69
|
export interface OverlaySource {
|
|
70
|
+
/** The live header index this activation contributes. */
|
|
41
71
|
current: HeaderIndex;
|
|
72
|
+
/**
|
|
73
|
+
* Optional live key resolver. When present, requests to a matched route are
|
|
74
|
+
* signed with the returned keys in order and failed over across them. Read as
|
|
75
|
+
* a live property so an activation can begin routing keys after install.
|
|
76
|
+
*/
|
|
77
|
+
keys?: (context: KeyRouteContext) => Promise<readonly KeyCandidate[]>;
|
|
78
|
+
/** Combines a GET model listing across the resolved key candidates. */
|
|
79
|
+
modelListing?: (context: ModelListingContext) => Promise<Response | undefined>;
|
|
42
80
|
}
|
|
43
81
|
/**
|
|
44
82
|
* Install (or join) the process-wide header wrapper.
|
|
45
|
-
* @param source - the live index this activation contributes.
|
|
83
|
+
* @param source - the live index (and optional key resolver) this activation contributes.
|
|
46
84
|
* @returns a handle whose `dispose` removes exactly this activation.
|
|
47
85
|
*/
|
|
48
86
|
export declare function installHeaderOverlay(source: OverlaySource): HeaderOverlay;
|
|
49
87
|
/** Whether this plugin's wrapper currently owns the global fetch (diagnostics). */
|
|
50
88
|
export declare function headerOverlayInstalled(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* The fetch beneath this plugin's wrapper.
|
|
91
|
+
*
|
|
92
|
+
* Used by callers that compose their OWN credential for a request — the model
|
|
93
|
+
* probe and the per-key discovery pass build the auth header from a specific
|
|
94
|
+
* reference, so letting the wrapper re-sign them with the route's FIRST key
|
|
95
|
+
* would probe the wrong credential. Reaching for the function under the wrapper
|
|
96
|
+
* keeps their composed headers exactly as built, while still honouring any
|
|
97
|
+
* wrapper some other plugin installed first. When this plugin's wrapper is not
|
|
98
|
+
* the live global (nothing to bypass), the live fetch is returned unchanged.
|
|
99
|
+
*/
|
|
100
|
+
export declare function headerOverlayBypass(): typeof globalThis.fetch;
|
|
51
101
|
/** The empty index, re-exported so callers building one need a single import. */
|
|
52
102
|
export { emptyIndex };
|
package/lib/headers-pi-ai.d.ts
CHANGED
|
@@ -16,9 +16,39 @@
|
|
|
16
16
|
* @module dsh-model-think-level/headers-pi-ai
|
|
17
17
|
*/
|
|
18
18
|
import { type HeaderIndex } from './headers-core.js';
|
|
19
|
-
|
|
19
|
+
import { type KeyCandidate } from './key-route-core.js';
|
|
20
|
+
/**
|
|
21
|
+
* Forget which wire served or failed which model.
|
|
22
|
+
*
|
|
23
|
+
* The memories are process-wide optimisations: they may be dropped at any time
|
|
24
|
+
* without changing an answer, only the number of rejected round trips it takes
|
|
25
|
+
* to find one. Tests (and a host that swaps its provider configuration) call
|
|
26
|
+
* this to start from a clean slate.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resetWireMemories(): void;
|
|
29
|
+
/**
|
|
30
|
+
* The protocol a key actually dispatches on this route, and how much the model
|
|
31
|
+
* costs there, are decided by the one plan both seams share — see
|
|
32
|
+
* `planKeys` in the routing module. Nothing here ranks keys on its own: a second
|
|
33
|
+
* ordering would only be able to disagree with the wire the plan chose.
|
|
34
|
+
*/
|
|
35
|
+
/** What a key resolver is told about the request it must sign and dispatch. */
|
|
36
|
+
export interface PiAiKeyContext {
|
|
37
|
+
/** The provider route whose profile claims this request. */
|
|
38
|
+
readonly route: string;
|
|
39
|
+
/** The model id the request names, when it could be read. */
|
|
40
|
+
readonly model: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** A live route index shared with the fetch overlay, plus optional key routing. */
|
|
20
43
|
export interface PiAiHeaderSource {
|
|
21
44
|
current: HeaderIndex;
|
|
45
|
+
/**
|
|
46
|
+
* Optional live key resolver. When present, the proxy picks the ordered keys
|
|
47
|
+
* that may sign this request and (a) signs with each in turn, (b) re-dispatches
|
|
48
|
+
* the request through a pinned key's own protocol, and (c) fails over to the
|
|
49
|
+
* next key when a stream errors before any content is emitted.
|
|
50
|
+
*/
|
|
51
|
+
keys?: (context: PiAiKeyContext) => Promise<readonly KeyCandidate[]>;
|
|
22
52
|
}
|
|
23
53
|
/** Handle returned for one adapter patch. */
|
|
24
54
|
export interface PiAiHeaderTransformHandle {
|
package/lib/index.d.ts
CHANGED
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import type { Context } from '@deepseek-ai/cordis';
|
|
16
16
|
import Schema from '@deepseek-ai/schemastery';
|
|
17
|
+
import { composeProbeHeaders } from './listing.js';
|
|
17
18
|
import { buildAutofillPatch } from './autofill.js';
|
|
18
19
|
/** Re-exported so the package entry keeps naming the patch builder. */
|
|
19
20
|
export { buildAutofillPatch };
|
|
21
|
+
/** Re-exported so the package entry keeps naming the probe-header composer. */
|
|
22
|
+
export { composeProbeHeaders };
|
|
20
23
|
/** Stable plugin id, matching the cordis.patch.yml row and the bundle id. */
|
|
21
24
|
export declare const name = "dsh-model-think-level";
|
|
22
25
|
/** Hard dependencies: the loader waits for these before calling apply. */
|
|
@@ -59,25 +62,6 @@ export interface Config {
|
|
|
59
62
|
}
|
|
60
63
|
/** Schemastery schema: Cordis validates the row config and fills defaults before apply(). */
|
|
61
64
|
export declare const Config: Schema<Config>;
|
|
62
|
-
/**
|
|
63
|
-
* Compose the raw-models probe request's headers, mirroring the discipline of
|
|
64
|
-
* the harness's own model discovery: the provider
|
|
65
|
-
* profile's configured request headers form the base (deployment-owned
|
|
66
|
-
* credentials like `x-api-key` ride along), `accept` is always JSON, and a
|
|
67
|
-
* resolved credential's Bearer overwrites a profile `authorization` — which
|
|
68
|
-
* survives only when no credential resolves (a route may authenticate through
|
|
69
|
-
* its configured headers alone). Anthropic Messages answers through
|
|
70
|
-
* `x-api-key` plus a fixed `anthropic-version`, and its Bearer arm is never
|
|
71
|
-
* used (a profile `authorization` survives untouched there, exactly as the
|
|
72
|
-
* official discovery leaves it). Entries Fetch would refuse are dropped
|
|
73
|
-
* rather than failing the probe. Harness attribution headers are deliberately
|
|
74
|
-
* not sent — this is a same-origin diagnostic, not a harness request.
|
|
75
|
-
* @param profileHeaders - the profile's raw `headers` dict (simply absent
|
|
76
|
-
* on older documents).
|
|
77
|
-
* @param apiKey - the resolved credential, when one resolved.
|
|
78
|
-
* @param api - the profile's wire protocol.
|
|
79
|
-
*/
|
|
80
|
-
export declare function composeProbeHeaders(profileHeaders: unknown, apiKey: string | undefined, api: string): Record<string, string>;
|
|
81
65
|
/**
|
|
82
66
|
* Apply the plugin: autofill undeclared models on boot and after every commit
|
|
83
67
|
* that touches the pi-ai namespace.
|