@loreai/core 0.14.1 → 0.16.0
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/bun/db.d.ts +11 -0
- package/dist/bun/db.d.ts.map +1 -1
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.d.ts.map +1 -1
- package/dist/bun/index.js +38 -200
- package/dist/bun/index.js.map +3 -3
- package/dist/bun/worker-model.d.ts +12 -80
- package/dist/bun/worker-model.d.ts.map +1 -1
- package/dist/node/db.d.ts +11 -0
- package/dist/node/db.d.ts.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +38 -200
- package/dist/node/index.js.map +3 -3
- package/dist/node/worker-model.d.ts +12 -80
- package/dist/node/worker-model.d.ts.map +1 -1
- package/dist/types/db.d.ts +11 -0
- package/dist/types/db.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/worker-model.d.ts +12 -80
- package/dist/types/worker-model.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/db.ts +53 -1
- package/src/index.ts +3 -0
- package/src/worker-model.ts +13 -364
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker model resolution.
|
|
3
3
|
*
|
|
4
|
-
* Background workers (distillation, curation, query expansion)
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Phase 1: structural checks (parsability, observation count, token bounds)
|
|
8
|
-
* Phase 2: LLM judge (session model rates candidate output vs reference)
|
|
4
|
+
* Background workers (distillation, curation, query expansion) use the session
|
|
5
|
+
* model by default. An explicit `workerModel` config override is supported for
|
|
6
|
+
* cases where the user wants to pin background work to a specific model.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Previously this module contained dynamic worker model selection with
|
|
9
|
+
* candidate discovery, two-phase validation (structural check + LLM judge),
|
|
10
|
+
* and fingerprint-based staleness detection. That complexity was removed in
|
|
11
|
+
* favor of always using the session model — A/B testing showed the quality
|
|
12
|
+
* gap on complex conversations wasn't worth the infrastructure cost.
|
|
12
13
|
*/
|
|
13
|
-
/** Minimal model info
|
|
14
|
+
/** Minimal model info — kept for downstream consumers. */
|
|
14
15
|
export type ModelInfo = {
|
|
15
16
|
id: string;
|
|
16
17
|
providerID: string;
|
|
@@ -26,80 +27,11 @@ export type ModelInfo = {
|
|
|
26
27
|
reasoning?: boolean;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
|
-
/** Result of a worker model validation stored in kv_meta. */
|
|
30
|
-
export type WorkerModelResult = {
|
|
31
|
-
modelID: string;
|
|
32
|
-
providerID: string;
|
|
33
|
-
fingerprint: string;
|
|
34
|
-
validatedAt: number;
|
|
35
|
-
judgeScore: number | null;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Select worker model candidates from the available models.
|
|
39
|
-
*
|
|
40
|
-
* Returns up to 2 candidates: cheapest overall + one tier below the session
|
|
41
|
-
* model. The session model itself is included (if it's the cheapest, the list
|
|
42
|
-
* has 1 entry and no comparison is needed).
|
|
43
|
-
*/
|
|
44
|
-
export declare function selectWorkerCandidates(sessionModel: {
|
|
45
|
-
id: string;
|
|
46
|
-
providerID: string;
|
|
47
|
-
cost: {
|
|
48
|
-
input: number;
|
|
49
|
-
};
|
|
50
|
-
}, providerModels: ModelInfo[]): ModelInfo[];
|
|
51
|
-
/**
|
|
52
|
-
* Compute a fingerprint from the model landscape. Changes when:
|
|
53
|
-
* - Models are added or removed from the provider
|
|
54
|
-
* - The session model changes
|
|
55
|
-
*/
|
|
56
|
-
export declare function computeModelFingerprint(providerID: string, sessionModelID: string, activeModelIDs: string[]): string;
|
|
57
|
-
export declare function getValidatedWorkerModel(providerID: string): WorkerModelResult | null;
|
|
58
|
-
export declare function storeValidatedWorkerModel(result: WorkerModelResult): void;
|
|
59
|
-
/** Clear a stored worker model validation (e.g. when the model is deprecated). */
|
|
60
|
-
export declare function clearValidatedWorkerModel(providerID: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* Check whether the stored validation is stale (fingerprint mismatch).
|
|
63
|
-
*/
|
|
64
|
-
export declare function isValidationStale(stored: WorkerModelResult | null, currentFingerprint: string): boolean;
|
|
65
|
-
export type StructuralCheckResult = {
|
|
66
|
-
passed: boolean;
|
|
67
|
-
observationCount: number;
|
|
68
|
-
tokenCount: number;
|
|
69
|
-
reason?: string;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Structural quality check: does the candidate distillation output meet
|
|
73
|
-
* minimum quality thresholds relative to the reference?
|
|
74
|
-
*/
|
|
75
|
-
export declare function structuralCheck(candidateObservations: string | null, referenceObservations: string): StructuralCheckResult;
|
|
76
|
-
export declare const WORKER_JUDGE_SYSTEM = "You are evaluating distillation quality. You will be given a REFERENCE distillation (produced by a capable model) and a CANDIDATE distillation (produced by a cheaper model) of the same conversation segment.\n\nRate the candidate on a scale of 1-5:\n5 = Captures all key facts and decisions, equivalent to reference\n4 = Captures most facts, minor omissions\n3 = Captures the essential facts, some detail loss acceptable\n2 = Missing important facts or technical details\n1 = Significantly incomplete or inaccurate\n\nRespond with ONLY a single digit (1-5).";
|
|
77
|
-
export declare function workerJudgeUser(reference: string, candidate: string): string;
|
|
78
|
-
/** Parse the judge's score from a response. Returns null on parse failure. */
|
|
79
|
-
export declare function parseJudgeScore(response: string): number | null;
|
|
80
|
-
import type { LLMClient } from "./types";
|
|
81
|
-
export type ValidationInput = {
|
|
82
|
-
llm: LLMClient;
|
|
83
|
-
providerID: string;
|
|
84
|
-
sessionModelID: string;
|
|
85
|
-
candidates: ModelInfo[];
|
|
86
|
-
/** Recent gen-0 distillation to use as reference (observations text). */
|
|
87
|
-
referenceObservations: string;
|
|
88
|
-
/** Source messages text for re-running distillation with candidates. */
|
|
89
|
-
sourceMessagesText: string;
|
|
90
|
-
/** Date string for the distillation prompt. */
|
|
91
|
-
date: string;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Run the two-phase quality validation for worker model candidates.
|
|
95
|
-
* Returns the cheapest passing candidate, or null if none pass.
|
|
96
|
-
*/
|
|
97
|
-
export declare function runValidation(input: ValidationInput): Promise<WorkerModelResult | null>;
|
|
98
30
|
/**
|
|
99
31
|
* Resolve the effective worker model for a given provider.
|
|
100
|
-
* Priority: explicit config
|
|
32
|
+
* Priority: explicit config override > session model (fallback).
|
|
101
33
|
*/
|
|
102
|
-
export declare function resolveWorkerModel(
|
|
34
|
+
export declare function resolveWorkerModel(_providerID: string, configWorkerModel?: {
|
|
103
35
|
providerID: string;
|
|
104
36
|
modelID: string;
|
|
105
37
|
}, configModel?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-model.d.ts","sourceRoot":"","sources":["../../src/worker-model.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-model.d.ts","sourceRoot":"","sources":["../../src/worker-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE;QACZ,KAAK,EAAE;YAAE,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC;QACzB,+DAA+D;QAC/D,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH,CAAC;AAMF;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,iBAAiB,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC3D,WAAW,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAMrD"}
|
package/dist/types/db.d.ts
CHANGED
|
@@ -19,4 +19,15 @@ export declare function loadForceMinLayer(sessionID: string): number;
|
|
|
19
19
|
* (consumed) to avoid unbounded growth.
|
|
20
20
|
*/
|
|
21
21
|
export declare function saveForceMinLayer(sessionID: string, layer: number): void;
|
|
22
|
+
/** Get a metadata value by key. Returns null if not found. */
|
|
23
|
+
export declare function getMeta(key: string): string | null;
|
|
24
|
+
/** Set a metadata value (upsert). */
|
|
25
|
+
export declare function setMeta(key: string, value: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get or create the installation instance ID.
|
|
28
|
+
*
|
|
29
|
+
* Generated once (UUID v4) on first call, then persisted in the metadata
|
|
30
|
+
* table across process restarts and upgrades.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getInstanceId(): string;
|
|
22
33
|
//# sourceMappingURL=db.d.ts.map
|
package/dist/types/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAsXtC,wBAAgB,EAAE,IAAI,QAAQ,CAkC7B;AAwGD,wBAAgB,KAAK,SAKpB;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1D;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAYxE;AAMD,8DAA8D;AAC9D,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKlD;AAED,qCAAqC;AACrC,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAMxD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAMtC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { runRecall, RECALL_TOOL_DESCRIPTION, RECALL_PARAM_DESCRIPTIONS, type Rec
|
|
|
10
10
|
export type { LoreMessage, LoreUserMessage, LoreAssistantMessage, LorePart, LoreTextPart, LoreReasoningPart, LoreToolPart, LoreGenericPart, LoreToolState, LoreToolStatePending, LoreToolStateRunning, LoreToolStateCompleted, LoreToolStateError, LoreMessageWithParts, LLMClient, } from "./types";
|
|
11
11
|
export { isTextPart, isReasoningPart, isToolPart } from "./types";
|
|
12
12
|
export { load, config, type LoreConfig } from "./config";
|
|
13
|
-
export { db, ensureProject, isFirstRun, projectId, projectName, loadForceMinLayer, saveForceMinLayer, close, } from "./db";
|
|
13
|
+
export { db, ensureProject, isFirstRun, projectId, projectName, loadForceMinLayer, saveForceMinLayer, getMeta, setMeta, getInstanceId, close, } from "./db";
|
|
14
14
|
export { transform, setModelLimits, setMaxLayer0Tokens, computeLayer0Cap, needsUrgentDistillation, calibrate, setLtmTokens, getLtmTokens, getLtmBudget, setForceMinLayer, getLastTransformedCount, getLastTransformEstimate, toolStripAnnotation, onIdleResume, getLastTurnAt, consumeCameOutOfIdle, setLastTurnAtForTest, inspectSessionState, } from "./gradient";
|
|
15
15
|
export { formatKnowledge, formatDistillations, DISTILLATION_SYSTEM, distillationUser, RECURSIVE_SYSTEM, recursiveUser, CURATOR_SYSTEM, curatorUser, CONSOLIDATION_SYSTEM, consolidationUser, QUERY_EXPANSION_SYSTEM, COMPACT_SUMMARY_TEMPLATE, buildCompactPrompt, } from "./prompt";
|
|
16
16
|
export { shouldImport, importFromFile, exportToFile, exportLoreFile, importLoreFile, shouldImportLoreFile, loreFileExists, LORE_FILE, } from "./agents-file";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAE7B,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE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Y,EACZ,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,QAAQ,EACR,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EACT,MAAM,EACN,CAAC,EACD,CAAC,EACD,EAAE,EACF,GAAG,EACH,IAAI,EACJ,CAAC,EACD,IAAI,EACJ,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Worker model resolution.
|
|
3
3
|
*
|
|
4
|
-
* Background workers (distillation, curation, query expansion)
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Phase 1: structural checks (parsability, observation count, token bounds)
|
|
8
|
-
* Phase 2: LLM judge (session model rates candidate output vs reference)
|
|
4
|
+
* Background workers (distillation, curation, query expansion) use the session
|
|
5
|
+
* model by default. An explicit `workerModel` config override is supported for
|
|
6
|
+
* cases where the user wants to pin background work to a specific model.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Previously this module contained dynamic worker model selection with
|
|
9
|
+
* candidate discovery, two-phase validation (structural check + LLM judge),
|
|
10
|
+
* and fingerprint-based staleness detection. That complexity was removed in
|
|
11
|
+
* favor of always using the session model — A/B testing showed the quality
|
|
12
|
+
* gap on complex conversations wasn't worth the infrastructure cost.
|
|
12
13
|
*/
|
|
13
|
-
/** Minimal model info
|
|
14
|
+
/** Minimal model info — kept for downstream consumers. */
|
|
14
15
|
export type ModelInfo = {
|
|
15
16
|
id: string;
|
|
16
17
|
providerID: string;
|
|
@@ -26,80 +27,11 @@ export type ModelInfo = {
|
|
|
26
27
|
reasoning?: boolean;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
|
-
/** Result of a worker model validation stored in kv_meta. */
|
|
30
|
-
export type WorkerModelResult = {
|
|
31
|
-
modelID: string;
|
|
32
|
-
providerID: string;
|
|
33
|
-
fingerprint: string;
|
|
34
|
-
validatedAt: number;
|
|
35
|
-
judgeScore: number | null;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Select worker model candidates from the available models.
|
|
39
|
-
*
|
|
40
|
-
* Returns up to 2 candidates: cheapest overall + one tier below the session
|
|
41
|
-
* model. The session model itself is included (if it's the cheapest, the list
|
|
42
|
-
* has 1 entry and no comparison is needed).
|
|
43
|
-
*/
|
|
44
|
-
export declare function selectWorkerCandidates(sessionModel: {
|
|
45
|
-
id: string;
|
|
46
|
-
providerID: string;
|
|
47
|
-
cost: {
|
|
48
|
-
input: number;
|
|
49
|
-
};
|
|
50
|
-
}, providerModels: ModelInfo[]): ModelInfo[];
|
|
51
|
-
/**
|
|
52
|
-
* Compute a fingerprint from the model landscape. Changes when:
|
|
53
|
-
* - Models are added or removed from the provider
|
|
54
|
-
* - The session model changes
|
|
55
|
-
*/
|
|
56
|
-
export declare function computeModelFingerprint(providerID: string, sessionModelID: string, activeModelIDs: string[]): string;
|
|
57
|
-
export declare function getValidatedWorkerModel(providerID: string): WorkerModelResult | null;
|
|
58
|
-
export declare function storeValidatedWorkerModel(result: WorkerModelResult): void;
|
|
59
|
-
/** Clear a stored worker model validation (e.g. when the model is deprecated). */
|
|
60
|
-
export declare function clearValidatedWorkerModel(providerID: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* Check whether the stored validation is stale (fingerprint mismatch).
|
|
63
|
-
*/
|
|
64
|
-
export declare function isValidationStale(stored: WorkerModelResult | null, currentFingerprint: string): boolean;
|
|
65
|
-
export type StructuralCheckResult = {
|
|
66
|
-
passed: boolean;
|
|
67
|
-
observationCount: number;
|
|
68
|
-
tokenCount: number;
|
|
69
|
-
reason?: string;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Structural quality check: does the candidate distillation output meet
|
|
73
|
-
* minimum quality thresholds relative to the reference?
|
|
74
|
-
*/
|
|
75
|
-
export declare function structuralCheck(candidateObservations: string | null, referenceObservations: string): StructuralCheckResult;
|
|
76
|
-
export declare const WORKER_JUDGE_SYSTEM = "You are evaluating distillation quality. You will be given a REFERENCE distillation (produced by a capable model) and a CANDIDATE distillation (produced by a cheaper model) of the same conversation segment.\n\nRate the candidate on a scale of 1-5:\n5 = Captures all key facts and decisions, equivalent to reference\n4 = Captures most facts, minor omissions\n3 = Captures the essential facts, some detail loss acceptable\n2 = Missing important facts or technical details\n1 = Significantly incomplete or inaccurate\n\nRespond with ONLY a single digit (1-5).";
|
|
77
|
-
export declare function workerJudgeUser(reference: string, candidate: string): string;
|
|
78
|
-
/** Parse the judge's score from a response. Returns null on parse failure. */
|
|
79
|
-
export declare function parseJudgeScore(response: string): number | null;
|
|
80
|
-
import type { LLMClient } from "./types";
|
|
81
|
-
export type ValidationInput = {
|
|
82
|
-
llm: LLMClient;
|
|
83
|
-
providerID: string;
|
|
84
|
-
sessionModelID: string;
|
|
85
|
-
candidates: ModelInfo[];
|
|
86
|
-
/** Recent gen-0 distillation to use as reference (observations text). */
|
|
87
|
-
referenceObservations: string;
|
|
88
|
-
/** Source messages text for re-running distillation with candidates. */
|
|
89
|
-
sourceMessagesText: string;
|
|
90
|
-
/** Date string for the distillation prompt. */
|
|
91
|
-
date: string;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Run the two-phase quality validation for worker model candidates.
|
|
95
|
-
* Returns the cheapest passing candidate, or null if none pass.
|
|
96
|
-
*/
|
|
97
|
-
export declare function runValidation(input: ValidationInput): Promise<WorkerModelResult | null>;
|
|
98
30
|
/**
|
|
99
31
|
* Resolve the effective worker model for a given provider.
|
|
100
|
-
* Priority: explicit config
|
|
32
|
+
* Priority: explicit config override > session model (fallback).
|
|
101
33
|
*/
|
|
102
|
-
export declare function resolveWorkerModel(
|
|
34
|
+
export declare function resolveWorkerModel(_providerID: string, configWorkerModel?: {
|
|
103
35
|
providerID: string;
|
|
104
36
|
modelID: string;
|
|
105
37
|
}, configModel?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-model.d.ts","sourceRoot":"","sources":["../../src/worker-model.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker-model.d.ts","sourceRoot":"","sources":["../../src/worker-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE;QACZ,KAAK,EAAE;YAAE,IAAI,EAAE,OAAO,CAAA;SAAE,CAAC;QACzB,+DAA+D;QAC/D,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH,CAAC;AAMF;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,iBAAiB,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAC3D,WAAW,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAMrD"}
|
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { join, dirname } from "path";
|
|
|
3
3
|
import { mkdirSync } from "fs";
|
|
4
4
|
import { homedir } from "os";
|
|
5
5
|
|
|
6
|
-
const SCHEMA_VERSION =
|
|
6
|
+
const SCHEMA_VERSION = 13;
|
|
7
7
|
|
|
8
8
|
const MIGRATIONS: string[] = [
|
|
9
9
|
`
|
|
@@ -350,6 +350,18 @@ const MIGRATIONS: string[] = [
|
|
|
350
350
|
ALTER TABLE distillations ADD COLUMN r_compression REAL;
|
|
351
351
|
ALTER TABLE distillations ADD COLUMN c_norm REAL;
|
|
352
352
|
`,
|
|
353
|
+
`
|
|
354
|
+
-- Version 13: Installation metadata table for telemetry and diagnostics.
|
|
355
|
+
--
|
|
356
|
+
-- Separate from kv_meta (plugin state) — this holds installation-scoped
|
|
357
|
+
-- values: instance_id, release_channel, etc. Has updated_at for tracking
|
|
358
|
+
-- when values last changed.
|
|
359
|
+
CREATE TABLE IF NOT EXISTS metadata (
|
|
360
|
+
key TEXT PRIMARY KEY,
|
|
361
|
+
value TEXT NOT NULL,
|
|
362
|
+
updated_at INTEGER NOT NULL
|
|
363
|
+
);
|
|
364
|
+
`,
|
|
353
365
|
];
|
|
354
366
|
|
|
355
367
|
function dataDir() {
|
|
@@ -490,6 +502,11 @@ function recoverMissingObjects(database: Database) {
|
|
|
490
502
|
key TEXT PRIMARY KEY,
|
|
491
503
|
value TEXT NOT NULL
|
|
492
504
|
);
|
|
505
|
+
CREATE TABLE IF NOT EXISTS metadata (
|
|
506
|
+
key TEXT PRIMARY KEY,
|
|
507
|
+
value TEXT NOT NULL,
|
|
508
|
+
updated_at INTEGER NOT NULL
|
|
509
|
+
);
|
|
493
510
|
`);
|
|
494
511
|
}
|
|
495
512
|
|
|
@@ -572,3 +589,38 @@ export function saveForceMinLayer(sessionID: string, layer: number): void {
|
|
|
572
589
|
.run(sessionID, layer, Date.now());
|
|
573
590
|
}
|
|
574
591
|
}
|
|
592
|
+
|
|
593
|
+
// ---------------------------------------------------------------------------
|
|
594
|
+
// Installation metadata (metadata table)
|
|
595
|
+
// ---------------------------------------------------------------------------
|
|
596
|
+
|
|
597
|
+
/** Get a metadata value by key. Returns null if not found. */
|
|
598
|
+
export function getMeta(key: string): string | null {
|
|
599
|
+
const row = db()
|
|
600
|
+
.query("SELECT value FROM metadata WHERE key = ?")
|
|
601
|
+
.get(key) as { value: string } | null;
|
|
602
|
+
return row?.value ?? null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** Set a metadata value (upsert). */
|
|
606
|
+
export function setMeta(key: string, value: string): void {
|
|
607
|
+
db()
|
|
608
|
+
.query(
|
|
609
|
+
"INSERT INTO metadata (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = ?, updated_at = ?",
|
|
610
|
+
)
|
|
611
|
+
.run(key, value, Date.now(), value, Date.now());
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Get or create the installation instance ID.
|
|
616
|
+
*
|
|
617
|
+
* Generated once (UUID v4) on first call, then persisted in the metadata
|
|
618
|
+
* table across process restarts and upgrades.
|
|
619
|
+
*/
|
|
620
|
+
export function getInstanceId(): string {
|
|
621
|
+
const existing = getMeta("instance_id");
|
|
622
|
+
if (existing) return existing;
|
|
623
|
+
const id = crypto.randomUUID();
|
|
624
|
+
setMeta("instance_id", id);
|
|
625
|
+
return id;
|
|
626
|
+
}
|