Реверснутый zcode с своими фишками и плагинами
Реверснутая ade zcode без z ai, с массовой загрузкой ключей, умным апи роутингом, плагином для командной разработки
Реверснутая ade zcode без z ai, с массовой загрузкой ключей, умным апи роутингом, плагином для командной разработки
// Патчи desktop-части форка: main (IPC пула ключей), preload (мост), renderer (UI в Model settings).
// Идемпотентно. Запуск: node tools/patch-desktop.mjs extracted/out
import fs from 'node:fs';
import path from 'node:path';
const OUT = path.resolve(process.argv[2] ?? 'extracted/out');
const MARK = 'zcode-key-pool';
function patchFile(rel, edits) {
const file = path.join(OUT, rel);
let src = fs.readFileSync(file, 'utf8');
if (!fs.existsSync(`${file}.orig`)) fs.copyFileSync(file, `${file}.orig`);
else src = fs.readFileSync(`${file}.orig`, 'utf8');
for (const [from, to, label] of edits) {
const n = src.split(from).length - 1;
if (n !== 1) throw new Error(`${rel}: anchor "${label}" found ${n} times`);
src = src.replace(from, typeof to === 'function' ? to(from) : to);
}
fs.writeFileSync(file, src);
console.log(`patched ${rel} (${edits.length} edits)`);
}
// ---------------------------------------------------------------- main
patchFile('main/index.js', [
['import{b as Uh,c as Fh}from"./chunk-ZLSRAMF6.js";', (s) => `import"./key-pool-main.js";/*${MARK}*/${s}`, 'main-import'],
]);
// ---------------------------------------------------------------- preload
const bridge =
`;try{S.contextBridge.exposeInMainWorld("zcodeKeyPool",{` +
`read:()=>S.ipcRenderer.invoke("key-pool:read"),` +
`write:p=>S.ipcRenderer.invoke("key-pool:write",p),` +
`checkKeys:id=>S.ipcRenderer.invoke("key-pool:check-keys",id),` +
`checkModels:(id,m)=>S.ipcRenderer.invoke("key-pool:check-models",id,m),` +
`fingerprint:k=>S.ipcRenderer.invoke("key-pool:fingerprint",k),` +
`listRemoteModels:id=>S.ipcRenderer.invoke("key-pool:list-remote-models",id),` +
`resetCooldowns:id=>S.ipcRenderer.invoke("key-pool:reset-cooldowns",id)` +
`})}catch(e){}/*${MARK}*/`;
patchFile('preload/index.cjs', [
['S.contextBridge.exposeInMainWorld("zcode",{', (s) => `${bridge.slice(1)};${s}`, 'preload-bridge'],
]);
// ---------------------------------------------------------------- renderer
const R = 'renderer/assets/styles-CQuzX8si.js';
patchFile(R, [
// модуль UI пула
[
'import{t as Gi}from"./react-BOoGTxqx.js";',
(s) => `${s}import{KeyPoolSection as __kpSection,ModelTierBadge as __kpTier,BulkAddModels as __kpBulk,RoutingToolbar as __kpToolbar}from"./key-pool-ui.js";/*${MARK}*/`,
'renderer-import',
],
// секция «Ключи и роутинг» под полем API key
[
'onToggleApiKeyVisibility:()=>j(e=>!e)}):null,(0,$.jsx)(hUn,{',
'onToggleApiKeyVisibility:()=>j(e=>!e)}):null,Re?(0,$.jsx)(__kpSection,{provider:e,apiKeyValue:O},`kp-${e.providerId}`):null,(0,$.jsx)(hUn,{',
'pool-section',
],
// бейдж уровня в строке модели
[
'kZt(e.modelId,e.config.properties?.inputFormat?.supportsImage,i)?(0,$.jsx)(uZt,{}):null]})',
'kZt(e.modelId,e.config.properties?.inputFormat?.supportsImage,i)?(0,$.jsx)(uZt,{}):null,(0,$.jsx)(__kpTier,{providerId:t,modelId:e.modelId})]})',
'tier-badge',
],
// «Добавить списком» рядом с «Add model»
[
'(0,$.jsxs)(X,{type:`button`,variant:`secondary`,size:`default`,className:`rounded-lg`,"data-testid":TRe,onClick:E,children:[(0,$.jsx)(vc,{"data-icon":`inline-start`,"aria-hidden":`true`}),f.formatMessage({id:`settings.modelProvider.addModel`})]})',
(s) => `(0,$.jsxs)(\`div\`,{className:\`flex items-center gap-2\`,children:[(0,$.jsx)(__kpBulk,{providerId:e,models:i,onAddModel:l}),${s}]})`,
'bulk-add',
],
// глобальный тумблер авто-роутинга в шапке раздела.
// В свежем бандле O3 — второй ребёнок: `children:e}),(0,$.jsx)(O3,{...})]})`.
// Оборачиваем в div и оставляем исходный `]})` после вызова.
[
'children:e}),(0,$.jsx)(O3,{onRefresh:a,onNew:s,refreshing:m,refreshLabel:m?n:t,newLabel:o,newTestId:uRe})]})',
(s) => `children:e}),(0,$.jsxs)(\`div\`,{className:\`flex items-center gap-2\`,children:[(0,$.jsx)(__kpToolbar,{}),${s.slice('children:e},'.length + 1)}]})`,
'toolbar',
],
]);