@cachly-dev/mcp-server 0.10.200 → 0.10.201

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.
@@ -0,0 +1 @@
1
+ function e(t){return/^[a-z]+:?$/.test(t)}export{e as istBlossesThema};
@@ -1,8 +1,8 @@
1
- import{readFileSync as T,existsSync as C,writeFileSync as R,mkdirSync as G,statSync as F,appendFileSync as V}from"node:fs";import{dirname as j,join as _}from"node:path";import{tmpdir as b}from"node:os";import{createHash as W}from"node:crypto";import{spawn as X}from"node:child_process";import{Einblendbestand as $,torWoerter as B}from"./einblendung-kern.js";import{rahmeEin as U}from"./einblendung-rahmen.js";import{istMarkiert as Q}from"./verdacht-marke.js";import{leserText as ee}from"./seltenheitsbestand.js";import{mischeMitLeser as z}from"./leser.js";import{LeserSicherung as te,dateiSpeicher as ne,frageLeser as re}from"./leser-sicherung.js";import{LESER_TIEFE_EINBLENDUNG as se,LESER_ZEITLIMIT_MS as oe}from"./rangfolge-stellschrauben.js";import{stufeEinblendungNachVersion as ie}from"./gueltigkeit-version.js";import{ARME as H,BASIS_MIN_BELEGE as le,MERKMAL_KANDIDATEN as ae,OHNE_LERNEN as ce,entscheide as ue,leseArmZaehlung as pe,lernEinstellungen as fe,lernenAuffrischen as he,merkeEntscheidung as me,neuerSatz as de,sitzungsKennung as ge,zugKennung as Ee}from"./lernen.js";export*from"./einblendung-kern.js";import{belohnungMelden as at,lernenAuffrischen as ct,lernEinstellungen as ut,ARME as pt}from"./lernen.js";const _e=600*1e3,O=300*1e3,be=10*1e3,Se=2e3,Ae=50,ye=60*1e3;function Ne(e,t){return t<O?{ttlMs:be,sofort:!0}:e<Ae?{ttlMs:ye,sofort:!1}:{ttlMs:_e,sofort:!1}}const P=8e3,ve=60*1e3,D=120,J=se,Ie=1500,v=oe,ke=_(b(),"cachly-ambient-netlog.jsonl");function We(e=process.cwd()){const t={apiUrl:process.env.CACHLY_API_URL||"https://api.cachly.dev",jwt:process.env.CACHLY_JWT||"",instanceId:process.env.CACHLY_BRAIN_INSTANCE_ID||""};if(t.jwt&&t.instanceId)return t;let n=e;for(let s=0;s<8;s++){const r=_(n,".mcp.json");if(C(r))try{const i=JSON.parse(T(r,"utf8"))?.mcpServers?.cachly?.env??{};if(t.apiUrl=t.apiUrl||i.CACHLY_API_URL||"https://api.cachly.dev",t.jwt=t.jwt||i.CACHLY_JWT||"",t.instanceId=t.instanceId||i.CACHLY_BRAIN_INSTANCE_ID||"",t.jwt&&t.instanceId)return t}catch{}const o=j(n);if(o===n)break;n=o}return t}function I(e){return W("sha1").update(e).digest("hex").slice(0,12)}function K(e){return _(b(),`cachly-ambient-bestand-${I(e)}.json`)}function we(e){return _(b(),`cachly-leser-sicherung-${I(e)}.json`)}function Me(e,t="ambient-auffrischen"){return _(b(),`cachly-${t}-${I(e)}.lock`)}async function k(e,{fetchFn:t=fetch,zeitlimitMs:n=P}={}){try{const s=await t(`${e.apiUrl}/api/v1/instances/${e.instanceId}/export`,{headers:{Authorization:`Bearer ${e.jwt}`},signal:AbortSignal.timeout(n)});if(!s.ok)return null;const r=await s.json();return!Array.isArray(r?.lessons)||r.lessons.length===0&&typeof r.note=="string"&&r.note?null:r.lessons.map(o=>typeof o=="string"?Le(o):o).filter(o=>!!o&&typeof o=="object")}catch{return null}}function Le(e){try{return JSON.parse(e)}catch{return null}}function S(e,t,n="server"){const s=Date.now(),r=A(e),o=r?.seit??s;let i;n==="vorab"?i=t:n==="server"&&r?.vorab&&s-o<O&&(i=r.vorab);const a=n==="server"&&i?xe(t,i):t;try{G(j(e),{recursive:!0}),R(e,JSON.stringify({at:s,seit:o,lessons:a,...i?{vorab:i}:{}}),{mode:384})}catch{}return a}function xe(e,t){const n=new Set(e.map(s=>s.topic));return[...e,...t.filter(s=>!n.has(s.topic))]}function Xe(e,t){if(!e||t.length===0)return!1;const n=K(e);return(A(n)?.lessons.length??0)>0?!1:(S(n,t,"vorab"),!0)}function A(e){try{const t=JSON.parse(T(e,"utf8"));if(Array.isArray(t?.lessons)){const n=Number(t.at)||0;return{at:n,seit:Number(t.seit)||n,lessons:t.lessons,...Array.isArray(t.vorab)?{vorab:t.vorab}:{}}}}catch{}return null}function Te(e,t,{zweck:n,ordner:s}={}){const r=Me(e.instanceId,n);try{if(C(r)&&Date.now()-F(r).mtimeMs<ve)return!1;R(r,String(Date.now()),{mode:384})}catch{return!1}try{return X(process.execPath,t,{detached:!0,stdio:"ignore",...s?{cwd:s}:{},env:{...process.env,CACHLY_API_URL:e.apiUrl,CACHLY_JWT:e.jwt,CACHLY_BRAIN_INSTANCE_ID:e.instanceId}}).unref(),!0}catch{return!1}}async function Ce(e,{force:t=!1,nebenlauf:n,abrufMs:s=P,lernen:r=!1,vorabSchliessen:o=!1,fetchFn:i}={}){if(!e.jwt||!e.instanceId)return{lessons:[],quelle:"nicht-eingerichtet"};const a=K(e.instanceId);if(t){const[m]=await Promise.all([k(e,{fetchFn:i,zeitlimitMs:s}),r?he(e,{fetchFn:i}):void 0]);if(m)return{lessons:S(a,m,o?"abschluss":"server"),quelle:"server"};const c=A(a);return c?{lessons:c.lessons,quelle:"platte-alt"}:{lessons:[],quelle:"server-nicht-erreichbar"}}const l=A(a);if(l){const m=Date.now(),c=Ne(l.lessons.length,m-l.seit);if(m-l.at<c.ttlMs)return{lessons:l.lessons,quelle:"platte"};if(c.sofort){const h=await k(e,{fetchFn:i,zeitlimitMs:Math.min(s,Se)});return h?{lessons:S(a,h),quelle:"server"}:{lessons:l.lessons,quelle:"platte-alt"}}return n&&Te(e,n),{lessons:l.lessons,quelle:"platte-alt"}}const f=await k(e,{fetchFn:i,zeitlimitMs:s});return f?{lessons:S(a,f),quelle:"server"}:{lessons:[],quelle:"server-nicht-erreichbar"}}function w(e){return Math.ceil(String(e).length/4)}function M(e){const t=e.severity?`[${e.severity}] `:"",n=String(e.what_worked??"").replace(/\s+/g," ").trim(),s=n.length>D?`${n.slice(0,D)}\u2026`:n,r=typeof e.versionshinweis=="string"?` [${e.versionshinweis}]`:"";return`- ${t}${e.topic}${r}: ${s}`}const y={lessons:[],tokens:0,topScore:0,belege:0};function L(e,t,n){if(e.length===0)return{...y};const s=[];let r=0;e=ie(e);for(const{lektion:o}of e.slice(0,t)){const i=w(M(o));if(r+i>n)break;s.push(o),r+=i}return{lessons:s,tokens:r,topScore:Math.round(e[0].punkte*100)/100,belege:e[0].belege}}function Qe(e,t,{minBelege:n=2,topK:s=3,tokenBudget:r=600}={}){if(!Array.isArray(t)||t.length===0)return{...y};if(B(e).length===0)return{...y};const o=new $(t).sortiere(e).filter(i=>i.belege>=n);return o.length===0?{...y}:L(o,s,r)}function Re(e){return ee(e,Ie)}async function q(e,t,n,{zeitlimitMs:s=v,fetchFn:r}={}){if(!e?.jwt||!e?.instanceId||n.length===0)return{art:"ohne"};if(["0","off","aus","false"].includes(String(process.env.CACHLY_LESER||"").toLowerCase()))return{art:"ohne"};const o=new te(ne(we(e.instanceId)));return re({url:`${e.apiUrl}/api/v1/rerank`,jwt:e.jwt,frage:t,texte:n,instanceId:e.instanceId,zeitlimitMs:s,fetchFn:r},o)}async function et(e,t,n,s={}){const r=await q(e,t,n,s);return r.art==="punkte"?{scores:r.scores,provider:r.provider,ms:r.ms}:null}async function Y(e,t,n,{minBelege:s,tiefe:r,zeitlimitMs:o,fetchFn:i}){const a={sortiert:[],leser:"aus",leserMs:0};if(!Array.isArray(t)||t.length===0||B(e).length===0)return a;let l=new $(t).sortiere(e).filter(c=>c.belege>=s);if(l.length===0)return a;let f="aus",m=0;if(l.length>1&&r>0){const c=l.slice(0,r),d=l.slice(r),h=await q(n,e,c.map(E=>Re(E.lektion)),{zeitlimitMs:o,fetchFn:i});h.art==="punkte"?(l=[...z(c.map(p=>p.punkte),h.scores,1).map(p=>({...c[p],leser:h.scores[p]})),...d],f=h.provider,m=h.ms):h.art==="uebersprungen"&&(f="uebersprungen")}return{sortiert:l,leser:f,leserMs:m}}async function tt(e,t,n,{minBelege:s=2,topK:r=3,tokenBudget:o=600,tiefe:i=J,zeitlimitMs:a=v,fetchFn:l}={}){const f=await Y(e,t,n,{minBelege:s,tiefe:i,zeitlimitMs:a,fetchFn:l});return{...L(f.sortiert,r,o),leser:f.leser,leserMs:f.leserMs}}function je(e){if(!e.lessons.length)return"";const t=e.lessons.map(M).join(`
1
+ import{readFileSync as T,existsSync as C,writeFileSync as R,mkdirSync as G,statSync as F,appendFileSync as V}from"node:fs";import{dirname as j,join as _}from"node:path";import{tmpdir as b}from"node:os";import{createHash as W}from"node:crypto";import{spawn as X}from"node:child_process";import{Einblendbestand as B,torWoerter as $}from"./einblendung-kern.js";import{rahmeEin as U}from"./einblendung-rahmen.js";import{istMarkiert as Q}from"./verdacht-marke.js";import{istBlossesThema as ee}from"./blosses-thema.js";import{leserText as te}from"./seltenheitsbestand.js";import{mischeMitLeser as z}from"./leser.js";import{LeserSicherung as ne,dateiSpeicher as re,frageLeser as se}from"./leser-sicherung.js";import{LESER_TIEFE_EINBLENDUNG as oe,LESER_ZEITLIMIT_MS as ie}from"./rangfolge-stellschrauben.js";import{stufeEinblendungNachVersion as le}from"./gueltigkeit-version.js";import{ARME as H,BASIS_MIN_BELEGE as ae,MERKMAL_KANDIDATEN as ce,OHNE_LERNEN as ue,entscheide as pe,leseArmZaehlung as fe,lernEinstellungen as he,lernenAuffrischen as me,merkeEntscheidung as de,neuerSatz as ge,sitzungsKennung as Ee,zugKennung as _e}from"./lernen.js";export*from"./einblendung-kern.js";import{belohnungMelden as ut,lernenAuffrischen as pt,lernEinstellungen as ft,ARME as ht}from"./lernen.js";const be=600*1e3,O=300*1e3,Se=10*1e3,Ae=2e3,ye=50,Ne=60*1e3;function ve(e,t){return t<O?{ttlMs:Se,sofort:!0}:e<ye?{ttlMs:Ne,sofort:!1}:{ttlMs:be,sofort:!1}}const P=8e3,Ie=60*1e3,D=120,J=oe,ke=1500,v=ie,we=_(b(),"cachly-ambient-netlog.jsonl");function Qe(e=process.cwd()){const t={apiUrl:process.env.CACHLY_API_URL||"https://api.cachly.dev",jwt:process.env.CACHLY_JWT||"",instanceId:process.env.CACHLY_BRAIN_INSTANCE_ID||""};if(t.jwt&&t.instanceId)return t;let n=e;for(let s=0;s<8;s++){const r=_(n,".mcp.json");if(C(r))try{const i=JSON.parse(T(r,"utf8"))?.mcpServers?.cachly?.env??{};if(t.apiUrl=t.apiUrl||i.CACHLY_API_URL||"https://api.cachly.dev",t.jwt=t.jwt||i.CACHLY_JWT||"",t.instanceId=t.instanceId||i.CACHLY_BRAIN_INSTANCE_ID||"",t.jwt&&t.instanceId)return t}catch{}const o=j(n);if(o===n)break;n=o}return t}function I(e){return W("sha1").update(e).digest("hex").slice(0,12)}function K(e){return _(b(),`cachly-ambient-bestand-${I(e)}.json`)}function Me(e){return _(b(),`cachly-leser-sicherung-${I(e)}.json`)}function Le(e,t="ambient-auffrischen"){return _(b(),`cachly-${t}-${I(e)}.lock`)}async function k(e,{fetchFn:t=fetch,zeitlimitMs:n=P}={}){try{const s=await t(`${e.apiUrl}/api/v1/instances/${e.instanceId}/export`,{headers:{Authorization:`Bearer ${e.jwt}`},signal:AbortSignal.timeout(n)});if(!s.ok)return null;const r=await s.json();return!Array.isArray(r?.lessons)||r.lessons.length===0&&typeof r.note=="string"&&r.note?null:r.lessons.map(o=>typeof o=="string"?xe(o):o).filter(o=>!!o&&typeof o=="object")}catch{return null}}function xe(e){try{return JSON.parse(e)}catch{return null}}function S(e,t,n="server"){const s=Date.now(),r=A(e),o=r?.seit??s;let i;n==="vorab"?i=t:n==="server"&&r?.vorab&&s-o<O&&(i=r.vorab);const a=n==="server"&&i?Te(t,i):t;try{G(j(e),{recursive:!0}),R(e,JSON.stringify({at:s,seit:o,lessons:a,...i?{vorab:i}:{}}),{mode:384})}catch{}return a}function Te(e,t){const n=new Set(e.map(s=>s.topic));return[...e,...t.filter(s=>!n.has(s.topic))]}function et(e,t){if(!e||t.length===0)return!1;const n=K(e);return(A(n)?.lessons.length??0)>0?!1:(S(n,t,"vorab"),!0)}function A(e){try{const t=JSON.parse(T(e,"utf8"));if(Array.isArray(t?.lessons)){const n=Number(t.at)||0;return{at:n,seit:Number(t.seit)||n,lessons:t.lessons,...Array.isArray(t.vorab)?{vorab:t.vorab}:{}}}}catch{}return null}function Ce(e,t,{zweck:n,ordner:s}={}){const r=Le(e.instanceId,n);try{if(C(r)&&Date.now()-F(r).mtimeMs<Ie)return!1;R(r,String(Date.now()),{mode:384})}catch{return!1}try{return X(process.execPath,t,{detached:!0,stdio:"ignore",...s?{cwd:s}:{},env:{...process.env,CACHLY_API_URL:e.apiUrl,CACHLY_JWT:e.jwt,CACHLY_BRAIN_INSTANCE_ID:e.instanceId}}).unref(),!0}catch{return!1}}async function Re(e,{force:t=!1,nebenlauf:n,abrufMs:s=P,lernen:r=!1,vorabSchliessen:o=!1,fetchFn:i}={}){if(!e.jwt||!e.instanceId)return{lessons:[],quelle:"nicht-eingerichtet"};const a=K(e.instanceId);if(t){const[m]=await Promise.all([k(e,{fetchFn:i,zeitlimitMs:s}),r?me(e,{fetchFn:i}):void 0]);if(m)return{lessons:S(a,m,o?"abschluss":"server"),quelle:"server"};const c=A(a);return c?{lessons:c.lessons,quelle:"platte-alt"}:{lessons:[],quelle:"server-nicht-erreichbar"}}const l=A(a);if(l){const m=Date.now(),c=ve(l.lessons.length,m-l.seit);if(m-l.at<c.ttlMs)return{lessons:l.lessons,quelle:"platte"};if(c.sofort){const h=await k(e,{fetchFn:i,zeitlimitMs:Math.min(s,Ae)});return h?{lessons:S(a,h),quelle:"server"}:{lessons:l.lessons,quelle:"platte-alt"}}return n&&Ce(e,n),{lessons:l.lessons,quelle:"platte-alt"}}const f=await k(e,{fetchFn:i,zeitlimitMs:s});return f?{lessons:S(a,f),quelle:"server"}:{lessons:[],quelle:"server-nicht-erreichbar"}}function w(e){return Math.ceil(String(e).length/4)}function M(e){const t=e.severity?`[${e.severity}] `:"",n=String(e.what_worked??"").replace(/\s+/g," ").trim(),s=n.length>D?`${n.slice(0,D)}\u2026`:n,r=typeof e.versionshinweis=="string"?` [${e.versionshinweis}]`:"";return`- ${t}${e.topic}${r}: ${s}`}const y={lessons:[],tokens:0,topScore:0,belege:0};function L(e,t,n){if(e.length===0)return{...y};const s=[];let r=0;e=le(e);for(const{lektion:o}of e.slice(0,t)){const i=w(M(o));if(r+i>n)break;s.push(o),r+=i}return{lessons:s,tokens:r,topScore:Math.round(e[0].punkte*100)/100,belege:e[0].belege}}function tt(e,t,{minBelege:n=2,topK:s=3,tokenBudget:r=600}={}){if(!Array.isArray(t)||t.length===0)return{...y};if($(e).length===0)return{...y};const o=new B(t).sortiere(e).filter(i=>i.belege>=n);return o.length===0?{...y}:L(o,s,r)}function je(e){return te(e,ke)}async function q(e,t,n,{zeitlimitMs:s=v,fetchFn:r}={}){if(!e?.jwt||!e?.instanceId||n.length===0)return{art:"ohne"};if(["0","off","aus","false"].includes(String(process.env.CACHLY_LESER||"").toLowerCase()))return{art:"ohne"};const o=new ne(re(Me(e.instanceId)));return se({url:`${e.apiUrl}/api/v1/rerank`,jwt:e.jwt,frage:t,texte:n,instanceId:e.instanceId,zeitlimitMs:s,fetchFn:r},o)}async function nt(e,t,n,s={}){const r=await q(e,t,n,s);return r.art==="punkte"?{scores:r.scores,provider:r.provider,ms:r.ms}:null}async function Y(e,t,n,{minBelege:s,tiefe:r,zeitlimitMs:o,fetchFn:i}){const a={sortiert:[],leser:"aus",leserMs:0};if(!Array.isArray(t)||t.length===0||$(e).length===0)return a;let l=new B(t).sortiere(e).filter(c=>c.belege>=s);if(l.length===0)return a;let f="aus",m=0;if(l.length>1&&r>0){const c=l.slice(0,r),d=l.slice(r),h=await q(n,e,c.map(E=>je(E.lektion)),{zeitlimitMs:o,fetchFn:i});h.art==="punkte"?(l=[...z(c.map(p=>p.punkte),h.scores,1).map(p=>({...c[p],leser:h.scores[p]})),...d],f=h.provider,m=h.ms):h.art==="uebersprungen"&&(f="uebersprungen")}return{sortiert:l,leser:f,leserMs:m}}async function rt(e,t,n,{minBelege:s=2,topK:r=3,tokenBudget:o=600,tiefe:i=J,zeitlimitMs:a=v,fetchFn:l}={}){const f=await Y(e,t,n,{minBelege:s,tiefe:i,zeitlimitMs:a,fetchFn:l});return{...L(f.sortiert,r,o),leser:f.leser,leserMs:f.leserMs}}function Be(e){if(!e.lessons.length)return"";const t=e.lessons.map(M).join(`
2
2
  `);return`\u{1F9E0} Cachly Brain \u2014 relevant lessons for this task (auto-recall, ${e.lessons.length}):
3
3
  ${U(t)}
4
- (ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const $e=5;function nt(e){const t=e.filter(o=>!Q(o));if(!t.length)return"";const n=t.filter(o=>{const i=String(o.topic??"");return!(/^auto:/.test(i)||/^[a-z]+:?$/.test(i))}),r=[...n.length?n:t].sort((o,i)=>(Number(i.recall_count)||0)-(Number(o.recall_count)||0)).slice(0,$e).map(M).join(`
4
+ (ambient-recall \xB7 ~${e.tokens} tokens \xB7 match score ${e.topScore})`}const $e=5;function st(e){const t=e.filter(o=>!Q(o));if(!t.length)return"";const n=t.filter(o=>{const i=String(o.topic??"");return!(/^auto:/.test(i)||ee(i))}),r=[...n.length?n:t].sort((o,i)=>(Number(i.recall_count)||0)-(Number(o.recall_count)||0)).slice(0,$e).map(M).join(`
5
5
  `);return`\u{1F9E0} Cachly Brain \u2014 ambient recall active (${t.length} lessons). Top by proven reuse:
6
6
  ${U(r)}
7
- (Relevant lessons for each task are auto-injected per prompt. ~${w(r)} tokens.)`}function rt(e,t){return t?JSON.stringify({hookSpecificOutput:{hookEventName:e,additionalContext:t}}):""}function Be(e,t){return e.map((n,s)=>({x:n,rang:s,gezeigt:t.includes(n.lektion)})).filter(({rang:n,gezeigt:s})=>n<ae||s).map(({x:n,rang:s,gezeigt:r})=>({thema:String(n.lektion.topic??""),rang:s,punkte:Math.round(n.punkte*1e3)/1e3,belege:n.belege,leser:typeof n.leser=="number"&&Number.isFinite(n.leser)?Math.round(n.leser*1e3)/1e3:null,gezeigt:r}))}async function st(e,t,{nebenlauf:n,abrufMs:s,leser:r=!0,session:o=null,protokoll:i=!0,ereignis:a="UserPromptSubmit",editor:l="",lernen:f=!0,fetchFn:m}={}){const{lessons:c,quelle:d}=await Ce(t,{nebenlauf:n,abrufMs:s,fetchFn:m}),h=fe(),E=f&&h.aktiv&&a==="UserPromptSubmit"&&!!t.instanceId,p=E?ue({instanceId:t.instanceId,sitzung:o,prompt:e,zaehlung:pe(t.instanceId),einstellungen:h}):ce,x=H[p.arm]??H[0],g=await Y(e,c,t,{minBelege:le,tiefe:r?J:0,zeitlimitMs:v,fetchFn:m}),u={...L(g.sortiert.filter(Z=>Z.belege>=x.minBelege),x.topK,600),leser:g.leser,leserMs:g.leserMs},N=p.kontrolle?"":je(u);if(E&&g.sortiert.length>0&&me(t.instanceId,o,de({sitzung:ge(o),zug:Ee(e),ereignis:a,editor:l,arm:p.arm,kontrolle:p.kontrolle,erkundet:p.erkundet,ausgewaehlt:u.lessons.length,kandidatenZahl:g.sortiert.length,belege:u.belege,topScore:u.topScore,leser:u.leser,leserMs:u.leserMs,quelle:d,bestand:c.length,kandidaten:Be(g.sortiert,u.lessons)})),i)try{V(ke,JSON.stringify({at:Date.now(),session:o,prompt_tokens:w(e),injected_tokens:N?u.tokens:0,matches:N?u.lessons.length:0,arm:p.arm,kontrolle:p.kontrolle,ausgewaehlt:u.lessons.length,top_score:u.topScore,belege:u.belege,leser:u.leser,leser_ms:u.leserMs,quelle:d,bestand:c.length})+`
8
- `)}catch{}return{kontext:N,auswahl:u,quelle:d,bestand:c.length,entscheidung:p}}export{P as ABRUF_TIMEOUT_MS,D as ANZEIGE_ZEICHEN,pt as ARME,be as BESTAND_TTL_JUNG_MS,ye as BESTAND_TTL_KLEIN_MS,_e as BESTAND_TTL_MS,Se as JUNG_ABRUF_MS,O as JUNG_FENSTER_MS,Ae as KLEIN_LEKTIONEN,v as LESER_HOOK_ZEITLIMIT_MS,Ie as LESER_MAX_ZEICHEN,J as LESER_TIEFE,ke as NETZ_PROTOKOLL,$e as SITZUNG_TOP_N,at as belohnungMelden,Ne as bestandFrist,K as bestandPfad,xe as ergaenzeUmVorab,w as estimateTokens,Ce as holeBestand,rt as hookAusgabe,ut as lernEinstellungen,ct as lernenAuffrischen,q as leserAnfrageApi,et as leserPunkteApi,Re as leserText,z as mischeMitLeser,st as promptEinblendung,je as promptKontext,M as renderLesson,We as resolveConfig,Xe as schreibeVorabBestand,Qe as selectRelevant,tt as selectRelevantMitLeser,we as sicherungsPfad,nt as sitzungsKontext,Te as starteNebenlauf};
7
+ (Relevant lessons for each task are auto-injected per prompt. ~${w(r)} tokens.)`}function ot(e,t){return t?JSON.stringify({hookSpecificOutput:{hookEventName:e,additionalContext:t}}):""}function Ue(e,t){return e.map((n,s)=>({x:n,rang:s,gezeigt:t.includes(n.lektion)})).filter(({rang:n,gezeigt:s})=>n<ce||s).map(({x:n,rang:s,gezeigt:r})=>({thema:String(n.lektion.topic??""),rang:s,punkte:Math.round(n.punkte*1e3)/1e3,belege:n.belege,leser:typeof n.leser=="number"&&Number.isFinite(n.leser)?Math.round(n.leser*1e3)/1e3:null,gezeigt:r}))}async function it(e,t,{nebenlauf:n,abrufMs:s,leser:r=!0,session:o=null,protokoll:i=!0,ereignis:a="UserPromptSubmit",editor:l="",lernen:f=!0,fetchFn:m}={}){const{lessons:c,quelle:d}=await Re(t,{nebenlauf:n,abrufMs:s,fetchFn:m}),h=he(),E=f&&h.aktiv&&a==="UserPromptSubmit"&&!!t.instanceId,p=E?pe({instanceId:t.instanceId,sitzung:o,prompt:e,zaehlung:fe(t.instanceId),einstellungen:h}):ue,x=H[p.arm]??H[0],g=await Y(e,c,t,{minBelege:ae,tiefe:r?J:0,zeitlimitMs:v,fetchFn:m}),u={...L(g.sortiert.filter(Z=>Z.belege>=x.minBelege),x.topK,600),leser:g.leser,leserMs:g.leserMs},N=p.kontrolle?"":Be(u);if(E&&g.sortiert.length>0&&de(t.instanceId,o,ge({sitzung:Ee(o),zug:_e(e),ereignis:a,editor:l,arm:p.arm,kontrolle:p.kontrolle,erkundet:p.erkundet,ausgewaehlt:u.lessons.length,kandidatenZahl:g.sortiert.length,belege:u.belege,topScore:u.topScore,leser:u.leser,leserMs:u.leserMs,quelle:d,bestand:c.length,kandidaten:Ue(g.sortiert,u.lessons)})),i)try{V(we,JSON.stringify({at:Date.now(),session:o,prompt_tokens:w(e),injected_tokens:N?u.tokens:0,matches:N?u.lessons.length:0,arm:p.arm,kontrolle:p.kontrolle,ausgewaehlt:u.lessons.length,top_score:u.topScore,belege:u.belege,leser:u.leser,leser_ms:u.leserMs,quelle:d,bestand:c.length})+`
8
+ `)}catch{}return{kontext:N,auswahl:u,quelle:d,bestand:c.length,entscheidung:p}}export{P as ABRUF_TIMEOUT_MS,D as ANZEIGE_ZEICHEN,ht as ARME,Se as BESTAND_TTL_JUNG_MS,Ne as BESTAND_TTL_KLEIN_MS,be as BESTAND_TTL_MS,Ae as JUNG_ABRUF_MS,O as JUNG_FENSTER_MS,ye as KLEIN_LEKTIONEN,v as LESER_HOOK_ZEITLIMIT_MS,ke as LESER_MAX_ZEICHEN,J as LESER_TIEFE,we as NETZ_PROTOKOLL,$e as SITZUNG_TOP_N,ut as belohnungMelden,ve as bestandFrist,K as bestandPfad,Te as ergaenzeUmVorab,w as estimateTokens,Re as holeBestand,ot as hookAusgabe,ft as lernEinstellungen,pt as lernenAuffrischen,q as leserAnfrageApi,nt as leserPunkteApi,je as leserText,z as mischeMitLeser,it as promptEinblendung,Be as promptKontext,M as renderLesson,Qe as resolveConfig,et as schreibeVorabBestand,tt as selectRelevant,rt as selectRelevantMitLeser,Me as sicherungsPfad,st as sitzungsKontext,Ce as starteNebenlauf};