odant-work 1.0.45 → 1.0.47

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.
@@ -823,7 +823,9 @@ export async function localEmbed(ai, params = {}) {
823
823
  model: String(ai?.model || ai?.id || 'local-embed'),
824
824
  data: (res.embeddings || []).map((embedding, index) => ({ object: 'embedding', index, embedding })),
825
825
  dimensions: res.dimensions || 0,
826
- durationMs: res.durationMs || 0,
826
+ loadMs: Number(res.loadMs) || 0,
827
+ genMs: Number(res.genMs || res.durationMs) || 0,
828
+ durationMs: Number(res.genMs || res.durationMs) || 0,
827
829
  };
828
830
  }
829
831
 
@@ -841,7 +843,9 @@ export async function localRerank(ai, params = {}) {
841
843
  return {
842
844
  model: String(ai?.model || ai?.id || 'local-rerank'),
843
845
  results: res.results || [],
844
- durationMs: res.durationMs || 0,
846
+ loadMs: Number(res.loadMs) || 0,
847
+ genMs: Number(res.genMs || res.durationMs) || 0,
848
+ durationMs: Number(res.genMs || res.durationMs) || 0,
845
849
  };
846
850
  }
847
851
 
@@ -850,19 +854,23 @@ export async function localGenerateImage(ai, params = {}) {
850
854
  const prompt = String(params.prompt || params.post || '').trim();
851
855
  if (!prompt)
852
856
  throw new Error('generateImage: пустой prompt');
857
+ const isTurbo = /z-image|turbo/i.test(weightsDir) || /z-image|turbo/i.test(String(ai?.model || ai?.id || ''));
858
+ const defaultSteps = isTurbo ? 4 : 8;
853
859
  const res = await runWorkerOp({
854
860
  op: 'image',
855
861
  weightsDir,
856
862
  prompt,
857
863
  size: String(params.size || '512x512'),
858
- steps: Number(params.steps) || 8,
864
+ steps: Number(params.steps) || defaultSteps,
859
865
  seed: params.seed != null ? Number(params.seed) : 42,
860
866
  }, 360000);
861
867
  return {
862
868
  mime: res.mime || 'image/png',
863
869
  base64: res.base64,
864
870
  model: String(ai?.model || ai?.id || 'local-image'),
865
- durationMs: res.durationMs || 0,
871
+ loadMs: Number(res.loadMs) || 0,
872
+ genMs: Number(res.genMs || res.durationMs) || 0,
873
+ durationMs: Number(res.genMs || res.durationMs) || 0,
866
874
  };
867
875
  }
868
876
 
@@ -878,8 +886,16 @@ export async function localSpeak(ai, params = {}) {
878
886
  language: String(params.language || ai?.language || 'Russian'),
879
887
  instructions: String(params.instructions || ai?.instructions || '').trim(),
880
888
  voice: String(params.voice || ai?.voice || 'serena'),
889
+ ...(params.seed != null ? { seed: Number(params.seed) } : {}),
890
+ ...(params.refAudioBase64 ? { refAudioBase64: String(params.refAudioBase64) } : {}),
891
+ ...(params.refText ? { refText: String(params.refText) } : {}),
881
892
  }, 240000);
882
- return Buffer.from(res.audioBase64 || '', 'base64');
893
+ const buf = Buffer.from(res.audioBase64 || '', 'base64');
894
+ buf.loadMs = Number(res.loadMs) || 0;
895
+ buf.genMs = Number(res.genMs || res.durationMs) || 0;
896
+ buf.ttsKind = res.ttsKind || '';
897
+ buf.instructUsed = res.instructUsed || '';
898
+ return buf;
883
899
  }
884
900
 
885
901
  export async function localTranscribe(ai, params = {}) {
@@ -896,7 +912,9 @@ export async function localTranscribe(ai, params = {}) {
896
912
  return {
897
913
  text: String(res.text || '').trim(),
898
914
  model: String(ai?.model || ai?.id || 'local-stt'),
899
- durationMs: res.durationMs || 0,
915
+ loadMs: Number(res.loadMs) || 0,
916
+ genMs: Number(res.genMs || res.durationMs) || 0,
917
+ durationMs: Number(res.genMs || res.durationMs) || 0,
900
918
  };
901
919
  }
902
920
 
@@ -153,7 +153,22 @@ export function inspectWeightsDirectorySync(dirPath, platform = os.platform()) {
153
153
  const hasConfig = files.includes('config.json');
154
154
  const hasTokenizer = files.includes('tokenizer.json');
155
155
  const pendingDownload = hasParts || pendingState;
156
- const hasReadyWeights = !pendingDownload && (hasSafetensors || hasGguf || hasBuboManifest || hasHgn || hasHnpw || hasOther);
156
+ // Основные веса уже на диске — модель работоспособна, даже если в фоне докачиваются
157
+ // недостающие конфиги/подпапки (speech_tokenizer/, onnx/, индексы шардов).
158
+ // «Не скачана» должна означать отсутствие самих весов, а не наличие .part у второстепенных файлов.
159
+ const rootParts = raw.some(f => f.endsWith('.part') && !f.includes('/'));
160
+ const hasWeightBinaries = hasSafetensors || hasGguf || hasBuboManifest || hasHgn || hasHnpw || hasOther;
161
+ // Шардированный чекпоинт готов только когда скачаны все шарды и есть их индекс.
162
+ const shards = files
163
+ .map(f => /-(\d{5})-of-(\d{5})\.(safetensors|bin)$/i.exec(f))
164
+ .filter(Boolean);
165
+ let shardsComplete = true;
166
+ if (shards.length) {
167
+ const expected = Math.max(...shards.map(m => Number(m[2])));
168
+ const present = new Set(shards.map(m => m[1])).size;
169
+ shardsComplete = present >= expected && files.some(f => /\.index\.json$/i.test(f));
170
+ }
171
+ const hasReadyWeights = hasWeightBinaries && !rootParts && shardsComplete;
157
172
 
158
173
  let weightFormat = '';
159
174
  if (hasBuboManifest)