@loreai/core 0.15.0 → 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/index.js CHANGED
@@ -28988,208 +28988,10 @@ function importLoreFile(projectPath) {
28988
28988
  // src/worker-model.ts
28989
28989
  var worker_model_exports = {};
28990
28990
  __export(worker_model_exports, {
28991
- WORKER_JUDGE_SYSTEM: () => WORKER_JUDGE_SYSTEM,
28992
- clearValidatedWorkerModel: () => clearValidatedWorkerModel,
28993
- computeModelFingerprint: () => computeModelFingerprint,
28994
- getValidatedWorkerModel: () => getValidatedWorkerModel,
28995
- isValidationStale: () => isValidationStale,
28996
- parseJudgeScore: () => parseJudgeScore,
28997
- resolveWorkerModel: () => resolveWorkerModel,
28998
- runValidation: () => runValidation,
28999
- selectWorkerCandidates: () => selectWorkerCandidates,
29000
- storeValidatedWorkerModel: () => storeValidatedWorkerModel,
29001
- structuralCheck: () => structuralCheck,
29002
- workerJudgeUser: () => workerJudgeUser
28991
+ resolveWorkerModel: () => resolveWorkerModel
29003
28992
  });
29004
- var KV_PREFIX = "lore:worker_model:";
29005
- function selectWorkerCandidates(sessionModel, providerModels) {
29006
- const eligible = providerModels.filter(
29007
- (m) => m.providerID === sessionModel.providerID && m.status === "active" && m.capabilities.input.text
29008
- );
29009
- if (eligible.length === 0) return [];
29010
- const sorted = [...eligible].sort((a, b) => {
29011
- const costDiff = a.cost.input - b.cost.input;
29012
- if (costDiff !== 0) return costDiff;
29013
- const aReasoning = a.capabilities.reasoning ? 1 : 0;
29014
- const bReasoning = b.capabilities.reasoning ? 1 : 0;
29015
- return aReasoning - bReasoning;
29016
- });
29017
- const cheapest = sorted[0];
29018
- const belowSession = sorted.filter((m) => m.cost.input < sessionModel.cost.input).pop();
29019
- const candidates = /* @__PURE__ */ new Map();
29020
- candidates.set(cheapest.id, cheapest);
29021
- if (belowSession && belowSession.id !== cheapest.id) {
29022
- candidates.set(belowSession.id, belowSession);
29023
- }
29024
- if (cheapest.id === sessionModel.id || cheapest.cost.input >= sessionModel.cost.input) {
29025
- return [cheapest];
29026
- }
29027
- return [...candidates.values()];
29028
- }
29029
- function computeModelFingerprint(providerID, sessionModelID, activeModelIDs) {
29030
- const sorted = [...activeModelIDs].sort();
29031
- return sha256(
29032
- JSON.stringify({ providerID, sessionModelID, modelIDs: sorted })
29033
- );
29034
- }
29035
- function getValidatedWorkerModel(providerID) {
29036
- const row = db().query("SELECT value FROM kv_meta WHERE key = ?").get(`${KV_PREFIX}${providerID}`);
29037
- if (!row) return null;
29038
- try {
29039
- return JSON.parse(row.value);
29040
- } catch {
29041
- return null;
29042
- }
29043
- }
29044
- function storeValidatedWorkerModel(result) {
29045
- const key = `${KV_PREFIX}${result.providerID}`;
29046
- const value = JSON.stringify(result);
29047
- db().query(
29048
- "INSERT INTO kv_meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = ?"
29049
- ).run(key, value, value);
29050
- }
29051
- function clearValidatedWorkerModel(providerID) {
29052
- db().query("DELETE FROM kv_meta WHERE key = ?").run(`${KV_PREFIX}${providerID}`);
29053
- }
29054
- function isValidationStale(stored, currentFingerprint) {
29055
- if (!stored) return true;
29056
- return stored.fingerprint !== currentFingerprint;
29057
- }
29058
- function structuralCheck(candidateObservations, referenceObservations) {
29059
- if (candidateObservations == null || candidateObservations.length === 0) {
29060
- return { passed: false, observationCount: 0, tokenCount: 0, reason: candidateObservations === null ? "parse_failed" : "empty" };
29061
- }
29062
- const countObs = (text4) => text4.split("\n").filter((l) => l.trim().length > 0).length;
29063
- const refCount = countObs(referenceObservations);
29064
- const candCount = countObs(candidateObservations);
29065
- const candTokens = Math.ceil(candidateObservations.length / 3);
29066
- if (refCount > 0 && (candCount < refCount * 0.5 || candCount > refCount * 1.5)) {
29067
- return {
29068
- passed: false,
29069
- observationCount: candCount,
29070
- tokenCount: candTokens,
29071
- reason: `observation_count_${candCount}_vs_ref_${refCount}`
29072
- };
29073
- }
29074
- const refTokens = Math.ceil(referenceObservations.length / 3);
29075
- if (candTokens === 0) {
29076
- return { passed: false, observationCount: candCount, tokenCount: candTokens, reason: "empty" };
29077
- }
29078
- if (refTokens > 0 && candTokens > refTokens * 3) {
29079
- return {
29080
- passed: false,
29081
- observationCount: candCount,
29082
- tokenCount: candTokens,
29083
- reason: `token_count_${candTokens}_vs_ref_${refTokens}_3x`
29084
- };
29085
- }
29086
- return { passed: true, observationCount: candCount, tokenCount: candTokens };
29087
- }
29088
- var 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.
29089
-
29090
- Rate the candidate on a scale of 1-5:
29091
- 5 = Captures all key facts and decisions, equivalent to reference
29092
- 4 = Captures most facts, minor omissions
29093
- 3 = Captures the essential facts, some detail loss acceptable
29094
- 2 = Missing important facts or technical details
29095
- 1 = Significantly incomplete or inaccurate
29096
-
29097
- Respond with ONLY a single digit (1-5).`;
29098
- function workerJudgeUser(reference, candidate) {
29099
- return `<reference>
29100
- ${reference}
29101
- </reference>
29102
-
29103
- <candidate>
29104
- ${candidate}
29105
- </candidate>`;
29106
- }
29107
- function parseJudgeScore(response) {
29108
- const match = response.trim().match(/^([1-5])/);
29109
- if (!match) return null;
29110
- return parseInt(match[1], 10);
29111
- }
29112
- async function runValidation(input) {
29113
- const { llm, candidates, referenceObservations, sourceMessagesText, date: date5 } = input;
29114
- const userPrompt = distillationUser({
29115
- messages: sourceMessagesText,
29116
- date: date5
29117
- });
29118
- for (const candidate of candidates) {
29119
- if (candidate.id === input.sessionModelID) continue;
29120
- let candidateObservations = null;
29121
- try {
29122
- const raw = await llm.prompt(DISTILLATION_SYSTEM, userPrompt, {
29123
- model: { providerID: candidate.providerID, modelID: candidate.id },
29124
- workerID: "lore-distill",
29125
- thinking: false
29126
- });
29127
- if (raw) {
29128
- const match = raw.match(/<observations>([\s\S]*?)<\/observations>/);
29129
- candidateObservations = match ? match[1].trim() : raw.trim();
29130
- }
29131
- } catch (e) {
29132
- warn(`worker model validation: candidate ${candidate.id} failed:`, e);
29133
- continue;
29134
- }
29135
- const structural = structuralCheck(candidateObservations, referenceObservations);
29136
- if (!structural.passed) {
29137
- info(
29138
- `worker model validation: ${candidate.id} failed structural check: ${structural.reason}`
29139
- );
29140
- continue;
29141
- }
29142
- let judgeScore = null;
29143
- try {
29144
- const judgeResponse = await llm.prompt(
29145
- WORKER_JUDGE_SYSTEM,
29146
- workerJudgeUser(referenceObservations, candidateObservations),
29147
- { workerID: "lore-distill", thinking: false }
29148
- // use session model (no model override)
29149
- );
29150
- if (judgeResponse) {
29151
- judgeScore = parseJudgeScore(judgeResponse);
29152
- }
29153
- } catch (e) {
29154
- warn(`worker model validation: judge call failed for ${candidate.id}:`, e);
29155
- }
29156
- if (judgeScore !== null && judgeScore < 3) {
29157
- info(
29158
- `worker model validation: ${candidate.id} failed judge (score=${judgeScore})`
29159
- );
29160
- continue;
29161
- }
29162
- const fingerprint = computeModelFingerprint(
29163
- input.providerID,
29164
- input.sessionModelID,
29165
- candidates.map((c) => c.id)
29166
- );
29167
- const result = {
29168
- modelID: candidate.id,
29169
- providerID: candidate.providerID,
29170
- fingerprint,
29171
- validatedAt: Date.now(),
29172
- judgeScore
29173
- };
29174
- storeValidatedWorkerModel(result);
29175
- info(
29176
- `worker model validated: ${candidate.id} (judge=${judgeScore}) for provider ${input.providerID}`
29177
- );
29178
- return result;
29179
- }
29180
- clearValidatedWorkerModel(input.providerID);
29181
- info(
29182
- `worker model validation: no candidate passed for ${input.providerID} \u2014 cleared stale entry`
29183
- );
29184
- return null;
29185
- }
29186
- function resolveWorkerModel(providerID, configWorkerModel, configModel) {
28993
+ function resolveWorkerModel(_providerID, configWorkerModel, configModel) {
29187
28994
  if (configWorkerModel) return configWorkerModel;
29188
- const validated = getValidatedWorkerModel(providerID);
29189
- const MAX_AGE_MS = 24 * 60 * 60 * 1e3;
29190
- if (validated && Date.now() - validated.validatedAt <= MAX_AGE_MS) {
29191
- return { providerID: validated.providerID, modelID: validated.modelID };
29192
- }
29193
28995
  return configModel;
29194
28996
  }
29195
28997
  export {