npm SDK の概要
@sakutto/* は、Sakutto 拡張機能の中で使っている翻訳パイプラインやモデル管理、ブラウザ推論、OCR、PDF レイアウトを再利用できる TypeScript ライブラリ群です。ブラウザ拡張機能を使うだけなら、これらをインストールする必要はありません。
パッケージ一覧
Section titled “パッケージ一覧”| パッケージ | 役割 | インストール |
|---|---|---|
@sakutto/core |
PFML3 プロンプト、翻訳パイプライン、バッチ処理、キャッシュ、ローカルサーバークライアント | npm install @sakutto/core |
@sakutto/models |
PLaMo / PP-OCRv6 の検証付きダウンロード、再開、OPFS / Node ストレージ | npm install @sakutto/models |
@sakutto/runtime-wllama |
検証済み PLaMo GGUF をブラウザ内の wllama で実行 | npm install @sakutto/runtime-wllama |
@sakutto/ocr |
PP-OCRv6 パイプラインと ONNX Runtime Web アダプター | npm install @sakutto/ocr onnxruntime-web |
@sakutto/pdf |
PDF の行グループ化、レイアウト、訳文フィットの純粋関数 | npm install @sakutto/pdf |
用途別インストール
Section titled “用途別インストール”ブラウザで翻訳したい
Section titled “ブラウザで翻訳したい”npm install @sakutto/core @sakutto/models @sakutto/runtime-wllama翻訳モデルのダウンロード、検証、OPFS への保存、wllama での実行、翻訳パイプラインまでを組み合わせます。
ブラウザで OCR もしたい
Section titled “ブラウザで OCR もしたい”npm install @sakutto/core @sakutto/models @sakutto/ocr onnxruntime-webONNX Runtime Web は peer dependency です。OCR モデルと ONNX Runtime の WASM / worker ファイルは、自分のアプリのオリジンから配信します。
ローカル推論サーバーへ接続したい
Section titled “ローカル推論サーバーへ接続したい”npm install @sakutto/coreOpenAI 互換の /v1/completions エンドポイントへ PFML3 プロンプトを送るクライアントだけを使えます。
PDF レイアウトだけ使いたい
Section titled “PDF レイアウトだけ使いたい”npm install @sakutto/pdfPDF を開いたり描画したりする機能はありません。抽出済みの TextPiece を行にまとめ、レイアウトし、フォント幅の計測関数を使って訳文を収めるためのライブラリです。
最小の翻訳例
Section titled “最小の翻訳例”import { createTranslator } from '@sakutto/core';import { createModelManager, DEFAULT_MODEL_ID } from '@sakutto/models';import { openOpfsModelStore } from '@sakutto/models/browser';import { createWllamaRuntime } from '@sakutto/runtime-wllama';
const store = await openOpfsModelStore('my-app');const models = createModelManager({ store });
// ユーザーが PLaMo Community License に同意した後だけ呼び出します。await models.download(DEFAULT_MODEL_ID, { acceptLicense: 'plamo-community' });
const runtime = await createWllamaRuntime(await models.open());try { const translator = createTranslator({ runtime }); console.log(await translator.translateText('こんにちは', { src: 'ja', tgt: 'en' }));} finally { await runtime.dispose();} ブラウザで推論 Vite アプリでモデルを取得し、翻訳と OCR を動かす手順。
Node / ローカルサーバー ローカル推論プロセスへ安全に接続する最小例。
実行例リポジトリ web-vite と node-server の完全な example。