
AIなりきりチャット開発日記
一応SVGで書かせてみたけど・・・
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 850 650">
<defs>
<marker id="arrow" markerWidth="10" markerHeight="7" refX="0" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" fill="#444" />
</marker>
<style>
.text { font-family: 'Segoe UI', sans-serif; font-size: 13px; fill: #333 ; }
.title { font-weight: bold; font-size: 16px; fill: #2c3e50 ; }
.box { fill: #ffffff ; stroke: #444 ; stroke-width: 1.5; }
.frontend { fill: #e3f2fd ; stroke: #1976d2 ; }
.backend { fill: #fff3e0 ; stroke: #f57c00 ; }
.db { fill: #f1f8e9 ; stroke: #388e3c ; }
.external { fill: #f3e5f5 ; stroke: #7b1fa2 ; stroke-dasharray: 4; }
.note { font-size: 11px; fill: #666 ; }
</style>
</defs>
<!-- Title -->
<text x="425" y="30" text-anchor="middle" class="text title">Character Chat Rust 動作フロー (Tauri Architecture)</text>
<!-- Frontend (Svelte) -->
<rect x="50" y="70" width="220" height="530" rx="10" class="box frontend" />
<text x="160" y="95" text-anchor="middle" class="text title">Frontend (Svelte)</text>
<rect x="70" y="120" width="180" height="60" rx="5" class="box" />
<text x="160" y="145" text-anchor="middle" class="text">HTF エディタ</text>
<text x="160" y="165" text-anchor="middle" class="note">(性格・外見の設定)</text>
<rect x="70" y="220" width="180" height="120" rx="5" class="box" />
<text x="160" y="245" text-anchor="middle" class="text">チャット UI</text>
<text x="160" y="275" text-anchor="middle" class="note">メッセージ入力</text>
<text x="160" y="300" text-anchor="middle" class="note">画像生成ボタン</text>
<rect x="70" y="480" width="180" height="60" rx="5" class="box" />
<text x="160" y="515" text-anchor="middle" class="text">画像ビューア</text>
<!-- Backend (Rust/Tauri) -->
<rect x="340" y="70" width="250" height="530" rx="10" class="box backend" />
<text x="465" y="95" text-anchor="middle" class="text title">Backend (Rust)</text>
<rect x="360" y="120" width="210" height="40" rx="5" class="box" />
<text x="465" y="145" text-anchor="middle" class="text">AppState (HTF管理)</text>
<rect x="360" y="220" width="210" height="60" rx="5" class="box" />
<text x="465" y="245" text-anchor="middle" class="text">Chat Logic (send_message)</text>
<text x="465" y="265" text-anchor="middle" class="note">履歴取得 + プロンプト構築</text>
<rect x="360" y="320" width="210" height="80" rx="5" class="box" />
<text x="465" y="345" text-anchor="middle" class="text">Image Generation Logic</text>
<text x="465" y="370" text-anchor="middle" class="note">1. LLMでプロンプト作成</text>
<text x="465" y="390" text-anchor="middle" class="note">2. 画像生成API呼び出し</text>
<!-- Database (SQLite) -->
<rect x="650" y="70" width="160" height="180" rx="10" class="box db" />
<text x="730" y="95" text-anchor="middle" class="text title">SQLite DB</text>
<text x="730" y="130" text-anchor="middle" class="text">- settings (HTF)</text>
<text x="730" y="160" text-anchor="middle" class="text">- characters</text>
<text x="730" y="190" text-anchor="middle" class="text">- messages (履歴)</text>
<text x="730" y="220" text-anchor="middle" class="text">- episodes (記憶)</text>
<!-- External Service (Sophia Router) -->
<rect x="650" y="320" width="160" height="140" rx="10" class="box external" />
<text x="730" y="345" text-anchor="middle" class="text title">Sophia Router</text>
<text x="730" y="375" text-anchor="middle" class="text">(localhost:8081)</text>
<text x="730" y="405" text-anchor="middle" class="note">LLM (Gemini/Local)</text>
<text x="730" y="430" text-anchor="middle" class="note">Image (imagecreate)</text>
<!-- Arrows & Connections -->
<!-- Frontend to Backend -->
<line x1="270" y1="140" x2="340" y2="140" stroke="#444" marker-end="url(#arrow)" />
<line x1="270" y1="250" x2="340" y2="250" stroke="#444" marker-end="url(#arrow)" />
<line x1="270" y1="360" x2="340" y2="360" stroke="#444" marker-end="url(#arrow)" />
<!-- Backend to DB -->
<path d="M 590 140 L 640 140" fill="none" stroke="#444" marker-end="url(#arrow)" />
<path d="M 590 240 L 640 240" fill="none" stroke="#44パンダ船長、`character-chat-rust` の解析が完了いたしました。
このプロジェクトは **Tauri** を基盤とした高度なキャラクター対話クライアントであり、先程解析した `ai-openai-proxy`(ポート8081)をハブとして活用しています。
特筆すべきは、キャラクターの定義を「HTF (Hierarchy Task Framework)」という階層構造(Individual/Social/Relation/Worldなど)で管理し、それをシステムプロンプトに動的に変換して対話に反映させている点です。また、対話履歴をSQLiteで永続化し、文脈に応じた画像生成プロンプトの自動生成機能も備えています。
動作フローをSVGで視覚化いたしました。
```xml
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 700">
<defs>
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="0" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" fill="#333" />
</marker>
<style>
.text { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 13px; fill: #333 ; }
.title { font-weight: bold; font-size: 15px; }
.box { fill: #ffffff ; stroke: #333 ; stroke-width: 1.5; }
.frontend { fill: #fff9c4 ; stroke: #fbc02d ; }
.backend { fill: #e3f2fd ; stroke: #1976d2 ; }
.db { fill: #f1f8e9 ; stroke: #689f38 ; }
.external { fill: #fafafa ; stroke: #9e9e9e ; stroke-dasharray: 4; }
.highlight { fill: #fce4ec ; stroke: #c2185b ; font-weight: bold; }
</style>
</defs>
<!-- Title -->
<text x="450" y="30" text-anchor="middle" class="text title" font-size="18">Character Chat Rust (Tauri) 内部動作フロー</text>
<!-- Frontend (Svelte/Vite) -->
<rect x="50" y="80" width="220" height="580" rx="10" class="box frontend" />
<text x="160" y="105" text-anchor="middle" class="text title">Frontend (Svelte)</text>
<rect x="70" y="130" width="180" height="100" rx="5" class="box" />
<text x="160" y="155" text-anchor="middle" class="text">HTF Editor</text>
<text x="160" y="175" text-anchor="middle" class="text" font-size="10">(Personality, Appearance)</text>
<rect x="70" y="260" width="180" height="120" rx="5" class="box" />
<text x="160" y="285" text-anchor="middle" class="text">Chat Interface</text>
<text x="160" y="305" text-anchor="middle" class="text" font-size="10">(Message History, Input)</text>
<rect x="70" y="420" width="180" height="80" rx="5" class="box highlight" />
<text x="160" y="445" text-anchor="middle" class="text">Image Generator UI</text>
<text x="160" y="465" text-anchor="middle" class="text" font-size="10">(Auto Prompt Display)</text>
<!-- Backend (Rust/Tauri) -->
<rect x="340" y="80" width="260" height="580" rx="10" class="box backend" />
<text x="470" y="105" text-anchor="middle" class="text title">Backend (Rust / Tauri Commands)</text>
<!-- Commands -->
<rect x="360" y="130" width="220" height="40" rx="5" class="box" />
<text x="470" y="155" text-anchor="middle" class="text">update_htf / load_character</text>
<rect x="360" y="200" width="220" height="150" rx="5" class="box" />
<text x="470" y="225" text-anchor="middle" class="text title">send_message</text>
<text x="375" y="250" class="text" font-size="10">1. Convert HTF to System Prompt</text>
<text x="375" y="270" class="text" font-size="10">2. Fetch Context from DB</text>
<text x="375" y="290" class="text" font-size="10">3. API Request (Local/Remote)</text>
<text x="375" y="310" class="text" font-size="10">4. Save Response to DB</text>
<rect x="360" y="370" width="220" height="80" rx="5" class="box highlight" />
<text x="470" y="395" text-anchor="middle" class="text">generate_auto_image_prompt</text>
<text x="470" y="415" text-anchor="middle" class="text" font-size="9">(LLM analyzes chat to create prompt)</text>
<rect x="360" y="470" width="220" height="40" rx="5" class="box" />
<text x="470" y="495" text-anchor="middle" class="text">generate_char_image</text>
<!-- Database (SQLite) -->
<rect x="670" y="130" width="180" height="200" rx="10" class="box db" />
<text x="760" y="155" text-anchor="middle" class="text title">character_chat.db</text>
<text x="685" y="185" class="text" font-size="11">・settings (Current HTF)</text>
<text x="685" y="210" class="text" font-size="11">・characters (Saved HTF)</text>
<text x="685" y="235" class="text" font-size="11">・messages (Chat History)</text>
<text x="685" y="260" class="text" font-size="11">・episodes (Summaries)</text>
<!-- External Hub (ai-openai-proxy) -->
<rect x="670" y="450" width="180" height="100" rx="10" class="box external" />
<text x="760" y="475" text-anchor="middle" class="text title">Proxy Hub (8081)</text>
<text x="760" y="500" text-anchor="middle" class="text" font-size="10">ai-openai-proxy</text>
<text x="760" y="520" text-anchor="middle" class="text" font-size="9">(Gemini / llama.cpp / imagecreate)</text>
<!-- Connections -->
<!-- UI to Commands -->
<line x1="270" y1="150" x2="350" y2="150" stroke="#333" marker-end="url(#arrowhead)" />
<line x1="270" y1="300" x2="350" y2="300" stroke="#333" marker-end="url(#arrowhead)" />
<line x1="270" y1="440" x2="350" y2="440" stroke="#333" marker-end="url(#arrowhead)" />
<line x1="270" y1="490" x2="350" y2="490" stroke="#333" marker-end="url(#arrowhead)" />
<!-- Commands to DB -->
<path d="M 580 150 L 670 150" fill="none" stroke="#689f38" marker-end="url(#arrowhead)" />
<path d="M 580 270 L 670 270" fill="none" stroke="#689f38" marker-end="url(#arrowhead)" />
<path d="M 670 290 L 580 290" fill="none" stroke="#689f38" marker-end="url(#arrowhead)" />
<!-- Commands to Proxy -->
<path d="M 580 320 L 640 320 L 640 480 L 660 480" fill="none" stroke="#1976d2" marker-end="url(#arrowhead)" />
<path d="M 580 400 L 620 400 L 620 460 L 660 460" fill="none" stroke="#1976d2" marker-end="url(#arrowhead)" />
<path d="M 580 500 L 670 500" fill="none" stroke="#1976d2" marker-end="url(#arrowhead)" />
<!-- Legend -->
<rect x="50" y="580" width="180" height="90" rx="5" fill="#fff" stroke="#ccc" />
<text x="60" y="600" class="text" font-size="12" font-weight="bold">凡例:</text>
<rect x="60" y="610" width="15" height="15" class="frontend" /> <text x="80" y="622" class="text" font-size="10">UI (Svelte)</text>
<rect x="60" y="630" width="15" height="15" class="backend" /> <text x="80" y="642" class="text" font-size="10">Logic (Rust)</text>
<rect x="60" y="650" width="15" height="15" class="db" /> <text x="80" y="662" class="text" font-size="10">Storage (SQLite)</text>
</svg>
このSVG自体、なりきりチャットでHTFキャラクター@「ソフィア」にコマンド使えるしファイルにもアクセスできるから、プロジェクトを確認して、チャートにして。と軽く頼んだだけ。
今、このチャットアプリに俺のシアラ内何かが含まれているかもしれないと、確認しているところ。しかしrustってすげーなぁ。、
かけないよwww
