"""Register enabled Deck profiles in OpenWebUI; never read chats or credentials.""" import datetime,json,os,sqlite3,time from pathlib import Path TARGETS={'flash-next-strata-iq3':('Qwen3.8 Flash-Next Strata IQ3 XXS',262144,1),'flash-next-strata-iq3-512k':('Qwen3.8 Flash-Next Strata IQ3 XXS - 512K',524288,1),'flash-next-strata-iq3-dual':('Qwen3.8 Flash-Next Strata IQ3 XXS - Dual-Slot 2x262K',262144,2)} c=sqlite3.connect('/app/backend/data/webui.db');c.row_factory=sqlite3.Row;c.execute('BEGIN IMMEDIATE') base=c.execute('select * from model where id=?',('flash-next-strata-iq3',)).fetchone();assert base before={'models':[],'functions':{},'config':{}} for ident in [*TARGETS,'flash-next-strata-iq2']: r=c.execute('select * from model where id=?',(ident,)).fetchone();before['models'].append(dict(r) if r else {'id':ident,'absent':True}) for ident in ('athena_context_display','athena_tool_context_guard'): r=c.execute('select valves from function where id=?',(ident,)).fetchone() if r:before['functions'][ident]=r[0] key='chat.context_compaction.token_cap';r=c.execute('select value from config where key=?',(key,)).fetchone();before['config'][key]=r[0] if r else None folder=Path('/app/backend/data/settings-backups');folder.mkdir(exist_ok=True);p=folder/('strata-profiles-'+datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S%fZ')+'.json');fd=os.open(p,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600) with os.fdopen(fd,'w') as f:json.dump(before,f) now=int(time.time()) for ident,(name,context,slots) in TARGETS.items(): old=c.execute('select * from model where id=?',(ident,)).fetchone() row=dict(old or base);params=json.loads(row['params'] or '{}');params['compact_token_threshold']=context*85//100;meta=json.loads(row['meta'] or '{}');meta['description']=f'Strata IQ3: {slots} parallele Slots, je {context} Token Kontext. Zusätzliche Anfragen warten.' row.update(id=ident,name=name,params=json.dumps(params),meta=json.dumps(meta),updated_at=now,is_active=1) if not old:row.update(base_model_id=None,created_at=now) cols=list(row);c.execute('insert or replace into model ('+','.join(cols)+') values ('+','.join('?' for _ in cols)+')',[row[k] for k in cols]) c.execute('update model set is_active=0,updated_at=? where id=?',(now,'flash-next-strata-iq2')) for ident,raw in before['functions'].items(): v=json.loads(raw or '{}');w=v.get('profile_windows',{});as_string=isinstance(w,str);w=json.loads(w) if as_string else dict(w) for k,(_,context,_) in TARGETS.items():w[k]=context w.pop('flash-next-strata-iq2',None);v['profile_windows']=json.dumps(w,sort_keys=True) if as_string else w c.execute('update function set valves=?,updated_at=? where id=?',(json.dumps(v),now,ident)) c.execute('insert into config (key,value,updated_at) values (?,?,?) on conflict(key) do update set value=excluded.value,updated_at=excluded.updated_at',(key,json.dumps(524288*85//100),now));c.commit() for ident,(_,context,_) in TARGETS.items(): r=c.execute('select params,is_active from model where id=?',(ident,)).fetchone();assert r[1] and json.loads(r[0])['compact_token_threshold']==context*85//100 assert c.execute('select is_active from model where id=?',('flash-next-strata-iq2',)).fetchone()[0]==0 print(json.dumps({'models':{k:{'context':v[1],'slots':v[2],'threshold':v[1]*85//100} for k,v in TARGETS.items()},'global_cap':445644,'iq2_active':False,'verified':True}))