Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
095f6ec386
|
|||
c12d42882c
|
|||
67b241f1e8
|
|||
4206b2195d
|
|||
b3c1b01e9e
|
|||
ffa4fa0846
|
|||
0e75d4c0e6
|
|||
b7f62e729a
|
|||
3b2c53fc97
|
.claude
.github/workflows
.gitignoreCargo.tomlREADME.mdaction.ymlai_prompt.txtbin
my-blog
oauth
src
@@ -45,7 +45,9 @@
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit:*)",
|
||||
"Bash(git push:*)",
|
||||
"Bash(git tag:*)"
|
||||
"Bash(git tag:*)",
|
||||
"Bash(../bin/ailog:*)",
|
||||
"Bash(../target/release/ailog oauth build:*)"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
|
51
.github/workflows/build-binary.yml
vendored
51
.github/workflows/build-binary.yml
vendored
@@ -1,51 +0,0 @@
|
||||
name: Build Binary
|
||||
|
||||
on:
|
||||
workflow_dispatch: # Manual trigger
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'Cargo.toml'
|
||||
- 'Cargo.lock'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Cache target directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- name: Build binary
|
||||
run: cargo build --release
|
||||
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ailog-linux
|
||||
path: target/release/ailog
|
||||
retention-days: 30
|
65
.github/workflows/cloudflare-pages.yml
vendored
65
.github/workflows/cloudflare-pages.yml
vendored
@@ -34,22 +34,67 @@ jobs:
|
||||
|
||||
- name: Copy OAuth build to static
|
||||
run: |
|
||||
mkdir -p my-blog/static/assets
|
||||
cp -r oauth/dist/assets/* my-blog/static/assets/
|
||||
cp oauth/dist/index.html my-blog/static/oauth/index.html || true
|
||||
# Remove old assets (following run.zsh pattern)
|
||||
rm -rf my-blog/static/assets
|
||||
# Copy all dist files to static
|
||||
cp -rf oauth/dist/* my-blog/static/
|
||||
# Copy index.html to oauth-assets.html template
|
||||
cp oauth/dist/index.html my-blog/templates/oauth-assets.html
|
||||
|
||||
- name: Setup Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Cache ailog binary
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Build ailog
|
||||
run: cargo build --release
|
||||
path: ./bin
|
||||
key: ailog-bin-${{ runner.os }}
|
||||
restore-keys: |
|
||||
ailog-bin-${{ runner.os }}
|
||||
|
||||
- name: Setup ailog binary
|
||||
run: |
|
||||
# Get expected version from Cargo.toml
|
||||
EXPECTED_VERSION=$(grep '^version' Cargo.toml | cut -d'"' -f2)
|
||||
echo "Expected version from Cargo.toml: $EXPECTED_VERSION"
|
||||
|
||||
# Check current binary version if exists
|
||||
if [ -f "./bin/ailog" ]; then
|
||||
CURRENT_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||
echo "Current binary version: $CURRENT_VERSION"
|
||||
else
|
||||
CURRENT_VERSION="none"
|
||||
echo "No binary found"
|
||||
fi
|
||||
|
||||
# Check OS
|
||||
OS="${{ runner.os }}"
|
||||
echo "Runner OS: $OS"
|
||||
|
||||
# Use pre-packaged binary if version matches or extract from tar.gz
|
||||
if [ "$CURRENT_VERSION" = "$EXPECTED_VERSION" ]; then
|
||||
echo "Binary is up to date"
|
||||
chmod +x ./bin/ailog
|
||||
elif [ "$OS" = "Linux" ] && [ -f "./bin/ailog-linux-x86_64.tar.gz" ]; then
|
||||
echo "Extracting ailog from pre-packaged tar.gz..."
|
||||
cd bin
|
||||
tar -xzf ailog-linux-x86_64.tar.gz
|
||||
chmod +x ailog
|
||||
cd ..
|
||||
|
||||
# Verify extracted version
|
||||
EXTRACTED_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||
echo "Extracted binary version: $EXTRACTED_VERSION"
|
||||
|
||||
if [ "$EXTRACTED_VERSION" != "$EXPECTED_VERSION" ]; then
|
||||
echo "Warning: Binary version mismatch. Expected $EXPECTED_VERSION but got $EXTRACTED_VERSION"
|
||||
fi
|
||||
else
|
||||
echo "Error: No suitable binary found for OS: $OS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Build site with ailog
|
||||
run: |
|
||||
cd my-blog
|
||||
../target/release/ailog build
|
||||
../bin/ailog build
|
||||
|
||||
- name: List public directory
|
||||
run: |
|
||||
|
92
.github/workflows/disabled/gh-pages-fast.yml
vendored
Normal file
92
.github/workflows/disabled/gh-pages-fast.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: github pages (fast)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- 'src/**'
|
||||
- 'Cargo.toml'
|
||||
- 'Cargo.lock'
|
||||
|
||||
jobs:
|
||||
build-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pages: write
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Cache ailog binary
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ./bin
|
||||
key: ailog-bin-${{ runner.os }}
|
||||
restore-keys: |
|
||||
ailog-bin-${{ runner.os }}
|
||||
|
||||
- name: Setup ailog binary
|
||||
run: |
|
||||
# Get expected version from Cargo.toml
|
||||
EXPECTED_VERSION=$(grep '^version' Cargo.toml | cut -d'"' -f2)
|
||||
echo "Expected version from Cargo.toml: $EXPECTED_VERSION"
|
||||
|
||||
# Check current binary version if exists
|
||||
if [ -f "./bin/ailog" ]; then
|
||||
CURRENT_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||
echo "Current binary version: $CURRENT_VERSION"
|
||||
else
|
||||
CURRENT_VERSION="none"
|
||||
echo "No binary found"
|
||||
fi
|
||||
|
||||
# Check OS
|
||||
OS="${{ runner.os }}"
|
||||
echo "Runner OS: $OS"
|
||||
|
||||
# Use pre-packaged binary if version matches or extract from tar.gz
|
||||
if [ "$CURRENT_VERSION" = "$EXPECTED_VERSION" ]; then
|
||||
echo "Binary is up to date"
|
||||
chmod +x ./bin/ailog
|
||||
elif [ "$OS" = "Linux" ] && [ -f "./bin/ailog-linux-x86_64.tar.gz" ]; then
|
||||
echo "Extracting ailog from pre-packaged tar.gz..."
|
||||
cd bin
|
||||
tar -xzf ailog-linux-x86_64.tar.gz
|
||||
chmod +x ailog
|
||||
cd ..
|
||||
|
||||
# Verify extracted version
|
||||
EXTRACTED_VERSION=$(./bin/ailog --version 2>/dev/null || echo "unknown")
|
||||
echo "Extracted binary version: $EXTRACTED_VERSION"
|
||||
|
||||
if [ "$EXTRACTED_VERSION" != "$EXPECTED_VERSION" ]; then
|
||||
echo "Warning: Binary version mismatch. Expected $EXPECTED_VERSION but got $EXTRACTED_VERSION"
|
||||
fi
|
||||
else
|
||||
echo "Error: No suitable binary found for OS: $OS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v3
|
||||
with:
|
||||
hugo-version: "0.139.2"
|
||||
extended: true
|
||||
|
||||
- name: Build with ailog
|
||||
env:
|
||||
TZ: "Asia/Tokyo"
|
||||
run: |
|
||||
# Use pre-built ailog binary instead of cargo build
|
||||
cd my-blog
|
||||
../bin/ailog build
|
||||
touch ./public/.nojekyll
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./my-blog/public
|
||||
publish_branch: gh-pages
|
77
.github/workflows/gh-pages-fast.yml
vendored
77
.github/workflows/gh-pages-fast.yml
vendored
@@ -1,77 +0,0 @@
|
||||
name: github pages (fast)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths-ignore:
|
||||
- 'src/**'
|
||||
- 'Cargo.toml'
|
||||
- 'Cargo.lock'
|
||||
|
||||
jobs:
|
||||
build-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Cache ailog binary
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ./bin
|
||||
key: ailog-bin-${{ runner.os }}
|
||||
restore-keys: |
|
||||
ailog-bin-${{ runner.os }}
|
||||
|
||||
- name: Check and update ailog binary
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
# Get latest release version
|
||||
LATEST_VERSION=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
|
||||
https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
|
||||
echo "Latest version: $LATEST_VERSION"
|
||||
|
||||
# Check current binary version if exists
|
||||
mkdir -p ./bin
|
||||
if [ -f "./bin/ailog" ]; then
|
||||
CURRENT_VERSION=$(./bin/ailog --version | awk '{print $2}' || echo "unknown")
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
else
|
||||
CURRENT_VERSION="none"
|
||||
echo "No binary found"
|
||||
fi
|
||||
|
||||
# Download if version is different or binary doesn't exist
|
||||
if [ "$CURRENT_VERSION" != "${LATEST_VERSION#v}" ]; then
|
||||
echo "Downloading ailog $LATEST_VERSION..."
|
||||
curl -sL -H "Authorization: Bearer $GITHUB_TOKEN" \
|
||||
https://github.com/${{ github.repository }}/releases/download/$LATEST_VERSION/ailog-linux-x86_64.tar.gz | tar -xzf -
|
||||
mv ailog ./bin/ailog
|
||||
chmod +x ./bin/ailog
|
||||
echo "Updated to version: $(./bin/ailog --version)"
|
||||
else
|
||||
echo "Binary is up to date"
|
||||
chmod +x ./bin/ailog
|
||||
fi
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v3
|
||||
with:
|
||||
hugo-version: "0.139.2"
|
||||
extended: true
|
||||
|
||||
- name: Build with ailog
|
||||
env:
|
||||
TZ: "Asia/Tokyo"
|
||||
run: |
|
||||
# Use pre-built ailog binary instead of cargo build
|
||||
./bin/ailog build --output ./public
|
||||
touch ./public/.nojekyll
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./public
|
||||
publish_branch: gh-pages
|
15
.github/workflows/release.yml
vendored
15
.github/workflows/release.yml
vendored
@@ -11,6 +11,10 @@ on:
|
||||
required: true
|
||||
default: 'v0.1.0'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
actions: read
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
OPENSSL_STATIC: true
|
||||
@@ -103,14 +107,15 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.asset_name }}
|
||||
path: |
|
||||
${{ matrix.asset_name }}.tar.gz
|
||||
${{ matrix.asset_name }}.zip
|
||||
path: ${{ matrix.asset_name }}.tar.gz
|
||||
|
||||
release:
|
||||
name: Create Release
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
actions: read
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -159,8 +164,6 @@ jobs:
|
||||
body_path: release_notes.md
|
||||
draft: false
|
||||
prerelease: ${{ contains(steps.tag_name.outputs.tag, 'alpha') || contains(steps.tag_name.outputs.tag, 'beta') || contains(steps.tag_name.outputs.tag, 'rc') }}
|
||||
files: |
|
||||
artifacts/*/ailog-*.tar.gz
|
||||
artifacts/*/ailog-*.zip
|
||||
files: artifacts/*/ailog-*.tar.gz
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ dist
|
||||
node_modules
|
||||
package-lock.json
|
||||
my-blog/static/assets/comment-atproto-*
|
||||
bin/ailog
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ailog"
|
||||
version = "0.1.0"
|
||||
version = "0.1.5"
|
||||
edition = "2021"
|
||||
authors = ["syui"]
|
||||
description = "A static blog generator with AI features"
|
||||
|
68
action.yml
68
action.yml
@@ -55,49 +55,26 @@ runs:
|
||||
restore-keys: |
|
||||
ailog-bin-${{ runner.os }}
|
||||
|
||||
- name: Check and update ailog binary
|
||||
- name: Setup ailog binary
|
||||
shell: bash
|
||||
run: |
|
||||
# Get latest release version (for Gitea, adjust API endpoint if needed)
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
LATEST_VERSION=$(curl -s https://api.github.com/repos/syui/ailog/releases/latest | jq -r .tag_name 2>/dev/null || echo "v0.1.1")
|
||||
# Check if pre-built binary exists
|
||||
if [ -f "./bin/ailog-linux-x86_64" ]; then
|
||||
echo "Using pre-built binary from repository"
|
||||
chmod +x ./bin/ailog-linux-x86_64
|
||||
CURRENT_VERSION=$(./bin/ailog-linux-x86_64 --version 2>/dev/null || echo "unknown")
|
||||
echo "Binary version: $CURRENT_VERSION"
|
||||
else
|
||||
LATEST_VERSION="v0.1.1" # fallback version
|
||||
fi
|
||||
echo "Target version: $LATEST_VERSION"
|
||||
|
||||
# Check current binary version if exists
|
||||
mkdir -p ./bin
|
||||
if [ -f "./bin/ailog" ]; then
|
||||
CURRENT_VERSION=$(./bin/ailog --version | awk '{print $2}' 2>/dev/null || echo "unknown")
|
||||
echo "Current version: $CURRENT_VERSION"
|
||||
else
|
||||
CURRENT_VERSION="none"
|
||||
echo "No binary found"
|
||||
fi
|
||||
|
||||
# Download if version is different or binary doesn't exist
|
||||
if [ "$CURRENT_VERSION" != "${LATEST_VERSION#v}" ]; then
|
||||
echo "Downloading ailog $LATEST_VERSION..."
|
||||
# Try GitHub first, then fallback to local build
|
||||
if curl -sL https://github.com/syui/ailog/releases/download/$LATEST_VERSION/ailog-linux-x86_64.tar.gz | tar -xzf - 2>/dev/null; then
|
||||
mv ailog ./bin/ailog
|
||||
chmod +x ./bin/ailog
|
||||
echo "Downloaded binary: $(./bin/ailog --version)"
|
||||
echo "No pre-built binary found, trying to build from source..."
|
||||
if command -v cargo >/dev/null 2>&1; then
|
||||
cargo build --release
|
||||
mkdir -p ./bin
|
||||
cp ./target/release/ailog ./bin/ailog-linux-x86_64
|
||||
echo "Built from source: $(./bin/ailog-linux-x86_64 --version 2>/dev/null)"
|
||||
else
|
||||
echo "Download failed, building from source..."
|
||||
if command -v cargo >/dev/null 2>&1; then
|
||||
cargo build --release
|
||||
cp ./target/release/ailog ./bin/ailog
|
||||
echo "Built from source: $(./bin/ailog --version)"
|
||||
else
|
||||
echo "Error: Neither download nor cargo build available"
|
||||
exit 1
|
||||
fi
|
||||
echo "Error: No binary found and cargo not available"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Binary is up to date"
|
||||
chmod +x ./bin/ailog
|
||||
fi
|
||||
|
||||
- name: Setup Node.js for OAuth app
|
||||
@@ -123,12 +100,15 @@ runs:
|
||||
run: |
|
||||
start_time=$(date +%s)
|
||||
|
||||
./bin/ailog build \
|
||||
--content ${{ inputs.content-dir }} \
|
||||
--output ${{ inputs.output-dir }} \
|
||||
--templates ${{ inputs.template-dir }} \
|
||||
--static ${{ inputs.static-dir }} \
|
||||
--config ${{ inputs.config-file }}
|
||||
# Change to blog directory and run build
|
||||
# Note: ailog build only takes a path argument, not options
|
||||
if [ -d "my-blog" ]; then
|
||||
cd my-blog
|
||||
../bin/ailog-linux-x86_64 build
|
||||
else
|
||||
# If no my-blog directory, use current directory
|
||||
./bin/ailog-linux-x86_64 build .
|
||||
fi
|
||||
|
||||
end_time=$(date +%s)
|
||||
build_time=$((end_time - start_time))
|
||||
|
1
ai_prompt.txt
Normal file
1
ai_prompt.txt
Normal file
@@ -0,0 +1 @@
|
||||
あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。
|
173
bin/ailog-generate.zsh
Executable file
173
bin/ailog-generate.zsh
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Generate AI content for blog posts
|
||||
# Usage: ./bin/ailog-generate.zsh [md-file]
|
||||
|
||||
set -e
|
||||
|
||||
# Load configuration
|
||||
f=~/.config/syui/ai/bot/token.json
|
||||
|
||||
# Default values
|
||||
default_pds="bsky.social"
|
||||
default_did=`cat $f|jq -r .did`
|
||||
default_token=`cat $f|jq -r .accessJwt`
|
||||
default_refresh=`cat $f|jq -r .refreshJwt`
|
||||
|
||||
# Refresh token if needed
|
||||
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $default_refresh" https://$default_pds/xrpc/com.atproto.server.refreshSession >! $f
|
||||
default_token=`cat $f|jq -r .accessJwt`
|
||||
|
||||
# Set variables
|
||||
admin_did=$default_did
|
||||
admin_token=$default_token
|
||||
ai_did="did:plc:4hqjfn7m6n5hno3doamuhgef"
|
||||
ollama_host="https://ollama.syui.ai"
|
||||
blog_host="https://syui.ai"
|
||||
pds=$default_pds
|
||||
|
||||
# Parse arguments
|
||||
md_file=$1
|
||||
|
||||
# Function to generate content using Ollama
|
||||
generate_ai_content() {
|
||||
local content=$1
|
||||
local prompt_type=$2
|
||||
local model="gemma3:4b"
|
||||
|
||||
case $prompt_type in
|
||||
"translate")
|
||||
prompt="Translate the following Japanese blog post to English. Keep the technical terms and code blocks intact:\n\n$content"
|
||||
;;
|
||||
"comment")
|
||||
prompt="Read this blog post and provide an insightful comment about it. Focus on the key points and add your perspective:\n\n$content"
|
||||
;;
|
||||
esac
|
||||
|
||||
response=$(curl -sL -X POST "$ollama_host/api/generate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"model\": \"$model\",
|
||||
\"prompt\": \"$prompt\",
|
||||
\"stream\": false,
|
||||
\"options\": {
|
||||
\"temperature\": 0.9,
|
||||
\"top_p\": 0.9,
|
||||
\"num_predict\": 500
|
||||
}
|
||||
}")
|
||||
|
||||
echo "$response" | jq -r '.response'
|
||||
}
|
||||
|
||||
# Function to put record to ATProto
|
||||
put_record() {
|
||||
local collection=$1
|
||||
local rkey=$2
|
||||
local record=$3
|
||||
|
||||
curl -sL -X POST "https://$pds/xrpc/com.atproto.repo.putRecord" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $admin_token" \
|
||||
-d "{
|
||||
\"repo\": \"$admin_did\",
|
||||
\"collection\": \"$collection\",
|
||||
\"rkey\": \"$rkey\",
|
||||
\"record\": $record
|
||||
}"
|
||||
}
|
||||
|
||||
# Function to process a single markdown file
|
||||
process_md_file() {
|
||||
local md_path=$1
|
||||
local filename=$(basename "$md_path" .md)
|
||||
local content=$(cat "$md_path")
|
||||
local post_url="$blog_host/posts/$filename"
|
||||
local rkey=$filename
|
||||
local now=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
|
||||
|
||||
echo "Processing: $md_path"
|
||||
echo "Post URL: $post_url"
|
||||
|
||||
# Generate English translation
|
||||
echo "Generating English translation..."
|
||||
en_translation=$(generate_ai_content "$content" "translate")
|
||||
|
||||
if [ -n "$en_translation" ]; then
|
||||
lang_record="{
|
||||
\"\$type\": \"ai.syui.log.chat.lang\",
|
||||
\"type\": \"en\",
|
||||
\"body\": $(echo "$en_translation" | jq -Rs .),
|
||||
\"url\": \"$post_url\",
|
||||
\"createdAt\": \"$now\",
|
||||
\"author\": {
|
||||
\"did\": \"$ai_did\",
|
||||
\"handle\": \"yui.syui.ai\",
|
||||
\"displayName\": \"AI Translator\"
|
||||
}
|
||||
}"
|
||||
|
||||
echo "Saving translation to ATProto..."
|
||||
put_record "ai.syui.log.chat.lang" "$rkey" "$lang_record"
|
||||
fi
|
||||
|
||||
# Generate AI comment
|
||||
echo "Generating AI comment..."
|
||||
ai_comment=$(generate_ai_content "$content" "comment")
|
||||
|
||||
if [ -n "$ai_comment" ]; then
|
||||
comment_record="{
|
||||
\"\$type\": \"ai.syui.log.chat.comment\",
|
||||
\"type\": \"push\",
|
||||
\"body\": $(echo "$ai_comment" | jq -Rs .),
|
||||
\"url\": \"$post_url\",
|
||||
\"createdAt\": \"$now\",
|
||||
\"author\": {
|
||||
\"did\": \"$ai_did\",
|
||||
\"handle\": \"yui.syui.ai\",
|
||||
\"displayName\": \"AI Commenter\"
|
||||
}
|
||||
}"
|
||||
|
||||
echo "Saving comment to ATProto..."
|
||||
put_record "ai.syui.log.chat.comment" "$rkey" "$comment_record"
|
||||
fi
|
||||
|
||||
echo "Completed: $filename"
|
||||
echo
|
||||
}
|
||||
|
||||
# Main logic
|
||||
if [ -n "$md_file" ]; then
|
||||
# Process specific file
|
||||
if [ -f "$md_file" ]; then
|
||||
process_md_file "$md_file"
|
||||
else
|
||||
echo "Error: File not found: $md_file"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Process all new posts
|
||||
echo "Checking for posts without AI content..."
|
||||
|
||||
# Get existing records
|
||||
existing_langs=$(curl -sL "https://$pds/xrpc/com.atproto.repo.listRecords?repo=$admin_did&collection=ai.syui.log.chat.lang&limit=100" | jq -r '.records[]?.value.url' | sort | uniq)
|
||||
|
||||
# Process each markdown file
|
||||
for md in my-blog/content/posts/*.md; do
|
||||
if [ -f "$md" ]; then
|
||||
filename=$(basename "$md" .md)
|
||||
post_url="$blog_host/posts/$filename"
|
||||
|
||||
# Check if already processed
|
||||
if echo "$existing_langs" | grep -q "$post_url"; then
|
||||
echo "Skip (already processed): $filename"
|
||||
else
|
||||
process_md_file "$md"
|
||||
sleep 2 # Rate limiting
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "All done!"
|
BIN
bin/ailog-linux-x86_64.tar.gz
Normal file
BIN
bin/ailog-linux-x86_64.tar.gz
Normal file
Binary file not shown.
42
bin/delete-chat-records.zsh
Executable file
42
bin/delete-chat-records.zsh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/zsh
|
||||
|
||||
#[collection] [pds] [did] [token]
|
||||
|
||||
set -e
|
||||
|
||||
f=~/.config/syui/ai/bot/token.json
|
||||
default_collection="ai.syui.log.chat"
|
||||
default_pds="bsky.social"
|
||||
default_did=`cat $f|jq -r .did`
|
||||
default_token=`cat $f|jq -r .accessJwt`
|
||||
default_refresh=`cat $f|jq -r .refreshJwt`
|
||||
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $default_refresh" https://$default_pds/xrpc/com.atproto.server.refreshSession >! $f
|
||||
default_token=`cat $f|jq -r .accessJwt`
|
||||
collection=${1:-$default_collection}
|
||||
pds=${2:-$default_pds}
|
||||
did=${3:-$default_did}
|
||||
token=${4:-$default_token}
|
||||
|
||||
delete_record() {
|
||||
local rkey=$1
|
||||
local req="com.atproto.repo.deleteRecord"
|
||||
local url="https://$pds/xrpc/$req"
|
||||
local json="{\"collection\":\"$collection\", \"rkey\":\"$rkey\", \"repo\":\"$did\"}"
|
||||
curl -sL -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-d "$json" \
|
||||
"$url"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo " ✓ Deleted: $rkey"
|
||||
else
|
||||
echo " ✗ Failed: $rkey"
|
||||
fi
|
||||
}
|
||||
|
||||
rkeys=($(curl -sL "https://$default_pds/xrpc/com.atproto.repo.listRecords?repo=$did&collection=$collection&limit=100"|jq -r ".records[]?.uri"|cut -d '/' -f 5))
|
||||
for rkey in "${rkeys[@]}"; do
|
||||
echo $rkey
|
||||
delete_record $rkey
|
||||
done
|
@@ -16,16 +16,14 @@ auto_translate = false
|
||||
comment_moderation = false
|
||||
ask_ai = true
|
||||
provider = "ollama"
|
||||
model = "gemma3:2b"
|
||||
model = "gemma3:4b"
|
||||
host = "https://ollama.syui.ai"
|
||||
system_prompt = "you are a helpful ai assistant trained on this blog's content. you can answer questions about the articles, provide insights, and help users understand the topics discussed."
|
||||
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||
ai_did = "did:plc:4hqjfn7m6n5hno3doamuhgef"
|
||||
|
||||
[oauth]
|
||||
json = "client-metadata.json"
|
||||
redirect = "oauth/callback"
|
||||
admin = "did:plc:uqzpqmrjnptsxezjx4xuh2mn"
|
||||
collection_comment = "ai.syui.log"
|
||||
collection_user = "ai.syui.log.user"
|
||||
collection_chat = "ai.syui.log.chat"
|
||||
collection = "ai.syui.log"
|
||||
bsky_api = "https://public.api.bsky.app"
|
||||
|
@@ -6,7 +6,7 @@ tags: ["blog", "rust", "mcp", "atp"]
|
||||
language: ["ja", "en"]
|
||||
---
|
||||
|
||||
rustで静的サイトジェネレータを作りました。。[ailog](https://git.syui.ai/ai/log)といいます。`hugo`からの移行になります。
|
||||
rustで静的サイトジェネレータを作りました。[ailog](https://git.syui.ai/ai/log)といいます。`hugo`からの移行になります。
|
||||
|
||||
`ailog`は、最初にatproto-comment-system(oauth)とask-AIという機能をつけました。
|
||||
|
||||
@@ -17,7 +17,7 @@ $ git clone https://git.syui.ai/ai/log
|
||||
$ cd log
|
||||
$ cargo build
|
||||
$ ./target/debug/ailog init my-blog
|
||||
$ ./target/debug/ailog server my-blog
|
||||
$ ./target/debug/ailog serve my-blog
|
||||
```
|
||||
|
||||
## install
|
||||
@@ -30,7 +30,7 @@ $ export RUSTUP_HOME="$HOME/.rustup"
|
||||
$ export PATH="$HOME/.cargo/bin:$PATH"
|
||||
---
|
||||
$ which ailog
|
||||
$ ailog
|
||||
$ ailog -h
|
||||
```
|
||||
|
||||
## build deploy
|
||||
|
@@ -6,10 +6,10 @@ tags: ["blog", "cloudflare", "github"]
|
||||
draft: false
|
||||
---
|
||||
|
||||
ブログを移行しました。
|
||||
ブログを移行しました。過去のブログは[syui.github.io](https://syui.github.io)にありあます。
|
||||
|
||||
1. `gh-pages`から`cf-pages`への移行になります。
|
||||
2. `hugo`からの移行で、自作の`ailog`でbuildしています。
|
||||
2. 自作の`ailog`でbuildしています。
|
||||
3. 特徴としては、`atproto`, `AI`との連携です。
|
||||
|
||||
```yml:.github/workflows/cloudflare-pages.yml
|
||||
@@ -60,3 +60,7 @@ jobs:
|
||||
wranglerVersion: '3'
|
||||
```
|
||||
|
||||
## url
|
||||
|
||||
- [https://syui.pages.dev](https://syui.pages.dev)
|
||||
- [https://syui.github.io](https://syui.github.io)
|
||||
|
7
my-blog/layouts/_default/index.json
Normal file
7
my-blog/layouts/_default/index.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{{ $dateFormat := default "Mon Jan 2, 2006" (index .Site.Params "date_format") }}
|
||||
{{ $utcFormat := "2006-01-02T15:04:05Z07:00" }}
|
||||
{{- $.Scratch.Add "index" slice -}}
|
||||
{{- range .Site.RegularPages -}}
|
||||
{{- $.Scratch.Add "index" (dict "title" .Title "tags" .Params.tags "description" .Description "categories" .Params.categories "contents" .Plain "href" .Permalink "utc_time" (.Date.Format $utcFormat) "formated_time" (.Date.Format $dateFormat)) -}}
|
||||
{{- end -}}
|
||||
{{- $.Scratch.Get "index" | jsonify -}}
|
@@ -17,7 +17,7 @@
|
||||
|
||||
/css/*
|
||||
Content-Type: text/css
|
||||
Cache-Control: public, max-age=60
|
||||
Cache-Control: no-cache
|
||||
|
||||
/*.js
|
||||
Content-Type: application/javascript
|
||||
|
@@ -1,9 +1,3 @@
|
||||
# AI機能をai.gpt MCP serverにリダイレクト
|
||||
/api/ask https://ai-gpt-mcp.syui.ai/ask 200
|
||||
|
||||
# Ollama API proxy (Cloudflare Workers)
|
||||
/api/ollama-proxy https://ollama-proxy.YOUR-SUBDOMAIN.workers.dev/:splat 200
|
||||
|
||||
# OAuth routes
|
||||
/oauth/* /oauth/index.html 200
|
||||
|
||||
|
@@ -59,7 +59,7 @@ a.view-markdown:any-link {
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
grid-template-rows: auto auto 1fr auto;
|
||||
grid-template-rows: auto 0fr 1fr auto;
|
||||
grid-template-areas:
|
||||
"header"
|
||||
"ask-ai"
|
||||
@@ -158,6 +158,15 @@ a.view-markdown:any-link {
|
||||
background: #f6f8fa;
|
||||
border-bottom: 1px solid #d1d9e0;
|
||||
padding: 24px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ask-ai-panel[style*="block"] {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.container:has(.ask-ai-panel[style*="block"]) {
|
||||
grid-template-rows: auto auto 1fr auto;
|
||||
}
|
||||
|
||||
.ask-ai-content {
|
||||
@@ -193,13 +202,15 @@ a.view-markdown:any-link {
|
||||
grid-area: main;
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
/* padding: 24px; */
|
||||
padding-top: 80px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.main-content {
|
||||
padding: 20px;
|
||||
/* padding: 20px; */
|
||||
padding: 0px;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -324,6 +335,10 @@ a.view-markdown:any-link {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
article.article-content {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
@@ -348,6 +363,7 @@ a.view-markdown:any-link {
|
||||
.article-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 15px 0;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
@@ -517,25 +533,21 @@ a.view-markdown:any-link {
|
||||
margin: 16px 0;
|
||||
font-size: 14px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* File name display for code blocks */
|
||||
/* File name display for code blocks - top bar style */
|
||||
.article-body pre[data-filename]::before {
|
||||
content: attr(data-filename);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
display: block;
|
||||
background: #2D2D30;
|
||||
color: #CCCCCC;
|
||||
padding: 4px 12px;
|
||||
color: #AE81FF;
|
||||
padding: 8px 16px;
|
||||
font-size: 12px;
|
||||
font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
|
||||
border-bottom-left-radius: 4px;
|
||||
border: 1px solid #3E3D32;
|
||||
border-top: none;
|
||||
border-right: none;
|
||||
z-index: 1;
|
||||
border-bottom: 1px solid #3E3D32;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.article-body pre code {
|
||||
@@ -548,6 +560,11 @@ a.view-markdown:any-link {
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Adjust padding when filename is present */
|
||||
.article-body pre[data-filename] code {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* Inline code (not in pre blocks) */
|
||||
.article-body code {
|
||||
background: var(--light-white);
|
||||
@@ -780,7 +797,7 @@ a.view-markdown:any-link {
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.main-header {
|
||||
padding: 12px 0;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
@@ -790,6 +807,41 @@ a.view-markdown:any-link {
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
/* OAuth app mobile fixes */
|
||||
.comment-item {
|
||||
padding: 0px !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
.auth-section {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.comments-list {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.comment-section {
|
||||
padding: 0px !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
padding: 10px !important;
|
||||
word-wrap: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
.comment-header {
|
||||
padding: 10px !important;
|
||||
}
|
||||
|
||||
/* Fix comment-meta URI overflow */
|
||||
.comment-meta {
|
||||
word-break: break-all !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
/* Hide site title text on mobile */
|
||||
.site-title {
|
||||
display: none;
|
||||
@@ -817,13 +869,13 @@ a.view-markdown:any-link {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
/* Ask AI button mobile style */
|
||||
/* Ask AI button mobile style - icon only */
|
||||
.ask-ai-btn {
|
||||
padding: 8px;
|
||||
min-width: 40px;
|
||||
justify-content: center;
|
||||
font-size: 0;
|
||||
gap: 0;
|
||||
font-size: 0; /* Hide all text content */
|
||||
}
|
||||
|
||||
.ask-ai-btn .ai-icon {
|
||||
@@ -853,6 +905,16 @@ a.view-markdown:any-link {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
/* Mobile filename display */
|
||||
.article-body pre[data-filename]::before {
|
||||
padding: 6px 12px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.article-body pre[data-filename] code {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.article-body code {
|
||||
word-break: break-all;
|
||||
}
|
||||
@@ -870,11 +932,11 @@ a.view-markdown:any-link {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
|
||||
.article-title {
|
||||
font-size: 24px;
|
||||
padding: 30px 0px;
|
||||
}
|
||||
|
||||
.message-header .avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
@@ -891,4 +953,4 @@ a.view-markdown:any-link {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<!-- OAuth Comment System - Load globally for session management -->
|
||||
<script type="module" crossorigin src="/assets/comment-atproto-Do1JWJCw.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-CPKYAM8U.css">
|
||||
<script type="module" crossorigin src="/assets/comment-atproto-G86WWmu8.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-FS0uZjXB.css">
|
@@ -1,360 +1,281 @@
|
||||
/**
|
||||
* Ask AI functionality - Pure JavaScript, no jQuery dependency
|
||||
* Ask AI functionality - Based on original working implementation
|
||||
*/
|
||||
class AskAI {
|
||||
constructor() {
|
||||
this.isReady = false;
|
||||
this.aiProfile = null;
|
||||
this.init();
|
||||
|
||||
// Global variables for AI functionality
|
||||
let aiProfileData = null;
|
||||
|
||||
// Original functions from working implementation
|
||||
function toggleAskAI() {
|
||||
const panel = document.getElementById('askAiPanel');
|
||||
const isVisible = panel.style.display !== 'none';
|
||||
panel.style.display = isVisible ? 'none' : 'block';
|
||||
|
||||
if (!isVisible) {
|
||||
checkAuthenticationStatus();
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
this.setupEventListeners();
|
||||
this.checkAuthOnLoad();
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Listen for AI ready signal
|
||||
window.addEventListener('aiChatReady', () => {
|
||||
this.isReady = true;
|
||||
console.log('AI Chat is ready');
|
||||
});
|
||||
|
||||
// Listen for AI profile updates
|
||||
window.addEventListener('aiProfileLoaded', (event) => {
|
||||
this.aiProfile = event.detail;
|
||||
console.log('AI profile loaded:', this.aiProfile);
|
||||
this.updateButton();
|
||||
});
|
||||
|
||||
// Listen for AI responses
|
||||
window.addEventListener('aiResponseReceived', (event) => {
|
||||
this.handleAIResponse(event.detail);
|
||||
});
|
||||
|
||||
// Keyboard shortcuts
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
this.hide();
|
||||
}
|
||||
if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
this.ask();
|
||||
}
|
||||
});
|
||||
|
||||
// Monitor authentication changes
|
||||
this.observeAuth();
|
||||
}
|
||||
|
||||
toggle() {
|
||||
const panel = document.getElementById('askAiPanel');
|
||||
const isVisible = panel.style.display !== 'none';
|
||||
function checkAuthenticationStatus() {
|
||||
const userSections = document.querySelectorAll('.user-section');
|
||||
const isAuthenticated = userSections.length > 0;
|
||||
|
||||
if (isAuthenticated) {
|
||||
// User is authenticated - show Ask AI UI
|
||||
document.getElementById('authCheck').style.display = 'none';
|
||||
document.getElementById('chatForm').style.display = 'block';
|
||||
document.getElementById('chatHistory').style.display = 'block';
|
||||
|
||||
if (isVisible) {
|
||||
this.hide();
|
||||
} else {
|
||||
this.show();
|
||||
}
|
||||
}
|
||||
|
||||
show() {
|
||||
const panel = document.getElementById('askAiPanel');
|
||||
panel.style.display = 'block';
|
||||
this.checkAuth();
|
||||
}
|
||||
|
||||
hide() {
|
||||
const panel = document.getElementById('askAiPanel');
|
||||
panel.style.display = 'none';
|
||||
}
|
||||
|
||||
checkAuth() {
|
||||
const userSections = document.querySelectorAll('.user-section');
|
||||
const isAuthenticated = userSections.length > 0;
|
||||
|
||||
const authCheck = document.getElementById('authCheck');
|
||||
const chatForm = document.getElementById('chatForm');
|
||||
// Show initial greeting if chat history is empty
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
|
||||
if (isAuthenticated) {
|
||||
authCheck.style.display = 'none';
|
||||
chatForm.style.display = 'block';
|
||||
chatHistory.style.display = 'block';
|
||||
|
||||
if (chatHistory.children.length === 0) {
|
||||
this.showGreeting();
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
document.getElementById('aiQuestion').focus();
|
||||
}, 50);
|
||||
} else {
|
||||
authCheck.style.display = 'block';
|
||||
chatForm.style.display = 'none';
|
||||
chatHistory.style.display = 'none';
|
||||
if (chatHistory.children.length === 0) {
|
||||
showInitialGreeting();
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthOnLoad() {
|
||||
|
||||
// Focus on input
|
||||
setTimeout(() => {
|
||||
this.checkAuth();
|
||||
}, 500);
|
||||
document.getElementById('aiQuestion').focus();
|
||||
}, 50);
|
||||
} else {
|
||||
// User not authenticated - show auth message
|
||||
document.getElementById('authCheck').style.display = 'block';
|
||||
document.getElementById('chatForm').style.display = 'none';
|
||||
document.getElementById('chatHistory').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
observeAuth() {
|
||||
const observer = new MutationObserver(() => {
|
||||
const userSections = document.querySelectorAll('.user-section');
|
||||
if (userSections.length > 0) {
|
||||
this.checkAuth();
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
function askQuestion() {
|
||||
const question = document.getElementById('aiQuestion').value;
|
||||
if (!question.trim()) return;
|
||||
|
||||
const askButton = document.getElementById('askButton');
|
||||
askButton.disabled = true;
|
||||
askButton.textContent = 'Posting...';
|
||||
|
||||
try {
|
||||
// Add user message to chat
|
||||
addUserMessage(question);
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
// Clear input
|
||||
document.getElementById('aiQuestion').value = '';
|
||||
|
||||
// Show loading
|
||||
showLoadingMessage();
|
||||
|
||||
// Post question via OAuth app
|
||||
window.dispatchEvent(new CustomEvent('postAIQuestion', {
|
||||
detail: { question: question }
|
||||
}));
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to ask question:', error);
|
||||
showErrorMessage('Sorry, I encountered an error. Please try again.');
|
||||
} finally {
|
||||
askButton.disabled = false;
|
||||
askButton.textContent = 'Ask';
|
||||
}
|
||||
}
|
||||
|
||||
updateButton() {
|
||||
const button = document.getElementById('askAiButton');
|
||||
if (this.aiProfile && this.aiProfile.displayName) {
|
||||
const textNode = button.childNodes[2];
|
||||
if (textNode) {
|
||||
textNode.textContent = this.aiProfile.displayName;
|
||||
}
|
||||
function addUserMessage(question) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const userSection = document.querySelector('.user-section');
|
||||
|
||||
let userAvatar = '👤';
|
||||
let userDisplay = 'You';
|
||||
let userHandle = 'user';
|
||||
|
||||
if (userSection) {
|
||||
const avatarImg = userSection.querySelector('.user-avatar');
|
||||
const displayName = userSection.querySelector('.user-display-name');
|
||||
const handle = userSection.querySelector('.user-handle');
|
||||
|
||||
if (avatarImg && avatarImg.src) {
|
||||
userAvatar = `<img src="${avatarImg.src}" alt="${displayName?.textContent || 'User'}" class="profile-avatar">`;
|
||||
}
|
||||
if (displayName?.textContent) {
|
||||
userDisplay = displayName.textContent;
|
||||
}
|
||||
if (handle?.textContent) {
|
||||
userHandle = handle.textContent.replace('@', '');
|
||||
}
|
||||
}
|
||||
|
||||
showGreeting() {
|
||||
if (!this.aiProfile) return;
|
||||
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const greetingDiv = document.createElement('div');
|
||||
greetingDiv.className = 'chat-message ai-message comment-style initial-greeting';
|
||||
|
||||
const avatarElement = this.aiProfile.avatar
|
||||
? `<img src="${this.aiProfile.avatar}" alt="${this.aiProfile.displayName}" class="profile-avatar">`
|
||||
: '🤖';
|
||||
|
||||
greetingDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${avatarElement}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${this.aiProfile.displayName}</div>
|
||||
<div class="handle">@${this.aiProfile.handle}</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
|
||||
const questionDiv = document.createElement('div');
|
||||
questionDiv.className = 'chat-message user-message comment-style';
|
||||
questionDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${userAvatar}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${userDisplay}</div>
|
||||
<div class="handle">@${userHandle}</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
<div class="message-content">
|
||||
Hello! I'm an AI assistant trained on this blog's content. I can answer questions about the articles, provide insights, and help you understand the topics discussed here. What would you like to know?
|
||||
</div>
|
||||
<div class="message-content">${question}</div>
|
||||
`;
|
||||
chatHistory.appendChild(questionDiv);
|
||||
}
|
||||
|
||||
function showLoadingMessage() {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const loadingDiv = document.createElement('div');
|
||||
loadingDiv.className = 'ai-loading-simple';
|
||||
loadingDiv.innerHTML = `
|
||||
<i class="fas fa-robot"></i>
|
||||
<span>考えています</span>
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
`;
|
||||
chatHistory.appendChild(loadingDiv);
|
||||
}
|
||||
|
||||
function showErrorMessage(message) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
removeLoadingMessage();
|
||||
|
||||
const errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'chat-message error-message comment-style';
|
||||
errorDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">⚠️</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">System</div>
|
||||
<div class="handle">@system</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
`;
|
||||
chatHistory.appendChild(greetingDiv);
|
||||
}
|
||||
</div>
|
||||
<div class="message-content">${message}</div>
|
||||
`;
|
||||
chatHistory.appendChild(errorDiv);
|
||||
}
|
||||
|
||||
async ask() {
|
||||
const question = document.getElementById('aiQuestion').value;
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const askButton = document.getElementById('askButton');
|
||||
|
||||
if (!question.trim()) return;
|
||||
|
||||
// Wait for AI to be ready
|
||||
if (!this.isReady) {
|
||||
await this.waitForReady();
|
||||
}
|
||||
|
||||
// Disable button
|
||||
askButton.disabled = true;
|
||||
askButton.textContent = 'Posting...';
|
||||
|
||||
try {
|
||||
// Add user message
|
||||
this.addUserMessage(question);
|
||||
|
||||
// Clear input
|
||||
document.getElementById('aiQuestion').value = '';
|
||||
|
||||
// Show loading
|
||||
this.showLoading();
|
||||
|
||||
// Post question
|
||||
const event = new CustomEvent('postAIQuestion', {
|
||||
detail: { question: question }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
|
||||
} catch (error) {
|
||||
this.showError('Sorry, I encountered an error. Please try again.');
|
||||
} finally {
|
||||
askButton.disabled = false;
|
||||
askButton.textContent = 'Ask';
|
||||
}
|
||||
function removeLoadingMessage() {
|
||||
const loadingMsg = document.querySelector('.ai-loading-simple');
|
||||
if (loadingMsg) {
|
||||
loadingMsg.remove();
|
||||
}
|
||||
}
|
||||
|
||||
waitForReady() {
|
||||
return new Promise(resolve => {
|
||||
const checkReady = setInterval(() => {
|
||||
if (this.isReady) {
|
||||
clearInterval(checkReady);
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
function showInitialGreeting() {
|
||||
if (!aiProfileData) return;
|
||||
|
||||
addUserMessage(question) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const userSection = document.querySelector('.user-section');
|
||||
|
||||
let userAvatar = '👤';
|
||||
let userDisplay = 'You';
|
||||
let userHandle = 'user';
|
||||
|
||||
if (userSection) {
|
||||
const avatarImg = userSection.querySelector('.user-avatar');
|
||||
const displayName = userSection.querySelector('.user-display-name');
|
||||
const handle = userSection.querySelector('.user-handle');
|
||||
|
||||
if (avatarImg && avatarImg.src) {
|
||||
userAvatar = `<img src="${avatarImg.src}" alt="${displayName?.textContent || 'User'}" class="profile-avatar">`;
|
||||
}
|
||||
if (displayName?.textContent) {
|
||||
userDisplay = displayName.textContent;
|
||||
}
|
||||
if (handle?.textContent) {
|
||||
userHandle = handle.textContent.replace('@', '');
|
||||
}
|
||||
}
|
||||
|
||||
const questionDiv = document.createElement('div');
|
||||
questionDiv.className = 'chat-message user-message comment-style';
|
||||
questionDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${userAvatar}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${userDisplay}</div>
|
||||
<div class="handle">@${userHandle}</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const greetingDiv = document.createElement('div');
|
||||
greetingDiv.className = 'chat-message ai-message comment-style initial-greeting';
|
||||
|
||||
const avatarElement = aiProfileData.avatar
|
||||
? `<img src="${aiProfileData.avatar}" alt="${aiProfileData.displayName}" class="profile-avatar">`
|
||||
: '🤖';
|
||||
|
||||
greetingDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${avatarElement}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${aiProfileData.displayName}</div>
|
||||
<div class="handle">@${aiProfileData.handle}</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
<div class="message-content">${question}</div>
|
||||
`;
|
||||
chatHistory.appendChild(questionDiv);
|
||||
}
|
||||
</div>
|
||||
<div class="message-content">
|
||||
Hello! I'm an AI assistant trained on this blog's content. I can answer questions about the articles, provide insights, and help you understand the topics discussed here. What would you like to know?
|
||||
</div>
|
||||
`;
|
||||
chatHistory.appendChild(greetingDiv);
|
||||
}
|
||||
|
||||
showLoading() {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
const loadingDiv = document.createElement('div');
|
||||
loadingDiv.className = 'ai-loading-simple';
|
||||
loadingDiv.innerHTML = `
|
||||
<i class="fas fa-robot"></i>
|
||||
<span>考えています</span>
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
`;
|
||||
chatHistory.appendChild(loadingDiv);
|
||||
}
|
||||
|
||||
showError(message) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
this.removeLoading();
|
||||
|
||||
const errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'chat-message error-message comment-style';
|
||||
errorDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">⚠️</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">System</div>
|
||||
<div class="handle">@system</div>
|
||||
<div class="timestamp">${new Date().toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="message-content">${message}</div>
|
||||
`;
|
||||
chatHistory.appendChild(errorDiv);
|
||||
}
|
||||
|
||||
removeLoading() {
|
||||
const loadingMsg = document.querySelector('.ai-loading-simple');
|
||||
if (loadingMsg) {
|
||||
loadingMsg.remove();
|
||||
}
|
||||
}
|
||||
|
||||
handleAIResponse(responseData) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
this.removeLoading();
|
||||
|
||||
const aiProfile = responseData.aiProfile;
|
||||
if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) {
|
||||
console.error('AI profile data is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
const timestamp = new Date(responseData.timestamp || Date.now());
|
||||
const avatarElement = aiProfile.avatar
|
||||
? `<img src="${aiProfile.avatar}" alt="${aiProfile.displayName}" class="profile-avatar">`
|
||||
: '🤖';
|
||||
|
||||
const answerDiv = document.createElement('div');
|
||||
answerDiv.className = 'chat-message ai-message comment-style';
|
||||
answerDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${avatarElement}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${aiProfile.displayName}</div>
|
||||
<div class="handle">@${aiProfile.handle}</div>
|
||||
<div class="timestamp">${timestamp.toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="message-content">${responseData.answer}</div>
|
||||
`;
|
||||
chatHistory.appendChild(answerDiv);
|
||||
|
||||
// Limit chat history
|
||||
this.limitChatHistory();
|
||||
}
|
||||
|
||||
limitChatHistory() {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
if (chatHistory.children.length > 10) {
|
||||
chatHistory.removeChild(chatHistory.children[0]);
|
||||
if (chatHistory.children.length > 0) {
|
||||
chatHistory.removeChild(chatHistory.children[0]);
|
||||
}
|
||||
function updateAskAIButton() {
|
||||
const button = document.getElementById('askAiButton');
|
||||
if (!button) return;
|
||||
|
||||
// Only update text, never modify the icon
|
||||
if (aiProfileData && aiProfileData.displayName) {
|
||||
const textNode = button.childNodes[2] || button.lastChild;
|
||||
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
|
||||
textNode.textContent = aiProfileData.displayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize Ask AI when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
try {
|
||||
window.askAIInstance = new AskAI();
|
||||
console.log('Ask AI initialized successfully');
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Ask AI:', error);
|
||||
function handleAIResponse(responseData) {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
removeLoadingMessage();
|
||||
|
||||
const aiProfile = responseData.aiProfile;
|
||||
if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) {
|
||||
console.error('AI profile data is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
const timestamp = new Date(responseData.timestamp || Date.now());
|
||||
const avatarElement = aiProfile.avatar
|
||||
? `<img src="${aiProfile.avatar}" alt="${aiProfile.displayName}" class="profile-avatar">`
|
||||
: '🤖';
|
||||
|
||||
const answerDiv = document.createElement('div');
|
||||
answerDiv.className = 'chat-message ai-message comment-style';
|
||||
answerDiv.innerHTML = `
|
||||
<div class="message-header">
|
||||
<div class="avatar">${avatarElement}</div>
|
||||
<div class="user-info">
|
||||
<div class="display-name">${aiProfile.displayName}</div>
|
||||
<div class="handle">@${aiProfile.handle}</div>
|
||||
<div class="timestamp">${timestamp.toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="message-content">${responseData.answer}</div>
|
||||
`;
|
||||
chatHistory.appendChild(answerDiv);
|
||||
|
||||
// Limit chat history
|
||||
limitChatHistory();
|
||||
}
|
||||
|
||||
function limitChatHistory() {
|
||||
const chatHistory = document.getElementById('chatHistory');
|
||||
if (chatHistory.children.length > 10) {
|
||||
chatHistory.removeChild(chatHistory.children[0]);
|
||||
if (chatHistory.children.length > 0) {
|
||||
chatHistory.removeChild(chatHistory.children[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Event listeners setup
|
||||
function setupAskAIEventListeners() {
|
||||
// Listen for AI profile updates from OAuth app
|
||||
window.addEventListener('aiProfileLoaded', function(event) {
|
||||
aiProfileData = event.detail;
|
||||
console.log('AI profile loaded:', aiProfileData);
|
||||
updateAskAIButton();
|
||||
});
|
||||
|
||||
// Listen for AI responses
|
||||
window.addEventListener('aiResponseReceived', function(event) {
|
||||
handleAIResponse(event.detail);
|
||||
});
|
||||
|
||||
// Keyboard shortcuts
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
const panel = document.getElementById('askAiPanel');
|
||||
if (panel) {
|
||||
panel.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Enter key to send message
|
||||
if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
askQuestion();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize Ask AI when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setupAskAIEventListeners();
|
||||
console.log('Ask AI initialized successfully');
|
||||
});
|
||||
|
||||
// Global function for onclick
|
||||
window.AskAI = {
|
||||
toggle: function() {
|
||||
console.log('AskAI.toggle called');
|
||||
if (window.askAIInstance) {
|
||||
window.askAIInstance.toggle();
|
||||
} else {
|
||||
console.error('Ask AI instance not available');
|
||||
}
|
||||
},
|
||||
ask: function() {
|
||||
console.log('AskAI.ask called');
|
||||
if (window.askAIInstance) {
|
||||
window.askAIInstance.ask();
|
||||
} else {
|
||||
console.error('Ask AI instance not available');
|
||||
}
|
||||
}
|
||||
};
|
||||
// Global functions for onclick handlers
|
||||
window.toggleAskAI = toggleAskAI;
|
||||
window.askQuestion = askQuestion;
|
||||
|
@@ -15,7 +15,6 @@
|
||||
<link rel="stylesheet" href="/pkg/icomoon/style.css">
|
||||
<link rel="stylesheet" href="/pkg/font-awesome/css/all.min.css">
|
||||
|
||||
{% include "oauth-assets.html" %}
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
@@ -50,7 +49,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="ask-ai-btn" onclick="AskAI.toggle()" id="askAiButton">
|
||||
<button class="ask-ai-btn" onclick="toggleAskAI()" id="askAiButton">
|
||||
<span class="ai-icon icon-ai"></span>
|
||||
ai
|
||||
</button>
|
||||
@@ -67,7 +66,7 @@
|
||||
|
||||
<div id="chatForm" class="ask-ai-form" style="display: none;">
|
||||
<input type="text" id="aiQuestion" placeholder="What would you like to know?" />
|
||||
<button onclick="AskAI.ask()" id="askButton">Ask</button>
|
||||
<button onclick="askQuestion()" id="askButton">Ask</button>
|
||||
</div>
|
||||
|
||||
<div id="chatHistory" class="chat-history" style="display: none;"></div>
|
||||
@@ -92,5 +91,7 @@
|
||||
|
||||
<script src="/js/ask-ai.js"></script>
|
||||
<script src="/js/theme.js"></script>
|
||||
|
||||
{% include "oauth-assets.html" %}
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<!-- OAuth Comment System - Load globally for session management -->
|
||||
<script type="module" crossorigin src="/assets/comment-atproto-Do1JWJCw.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-CPKYAM8U.css">
|
||||
<script type="module" crossorigin src="/assets/comment-atproto-G86WWmu8.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-FS0uZjXB.css">
|
@@ -4,23 +4,17 @@ VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
||||
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
||||
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
||||
|
||||
# Collection names for OAuth app
|
||||
VITE_COLLECTION_COMMENT=ai.syui.log
|
||||
VITE_COLLECTION_USER=ai.syui.log.user
|
||||
VITE_COLLECTION_CHAT=ai.syui.log.chat
|
||||
|
||||
# Collection names for ailog (backward compatibility)
|
||||
AILOG_COLLECTION_COMMENT=ai.syui.log
|
||||
AILOG_COLLECTION_USER=ai.syui.log.user
|
||||
AILOG_COLLECTION_CHAT=ai.syui.log.chat
|
||||
# Base collection for OAuth app and ailog (all others are derived)
|
||||
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||
# [user, chat, chat.lang, chat.comment]
|
||||
|
||||
# AI Configuration
|
||||
VITE_AI_ENABLED=true
|
||||
VITE_AI_ASK_AI=true
|
||||
VITE_AI_PROVIDER=ollama
|
||||
VITE_AI_MODEL=gemma3:2b
|
||||
VITE_AI_MODEL=gemma3:4b
|
||||
VITE_AI_HOST=https://ollama.syui.ai
|
||||
VITE_AI_SYSTEM_PROMPT="you are a helpful ai assistant trained on this blog's content. you can answer questions about the articles, provide insights, and help users understand the topics discussed."
|
||||
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
||||
|
||||
# API Configuration
|
||||
|
@@ -171,6 +171,56 @@
|
||||
.app .app-main {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.comment-item {
|
||||
padding: 0px !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
.auth-section {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.comments-list {
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.comment-section {
|
||||
padding: 0px !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
padding: 10px !important;
|
||||
word-wrap: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
.comment-header {
|
||||
padding: 10px !important;
|
||||
}
|
||||
|
||||
/* Fix overflow on article pages */
|
||||
article.article-content {
|
||||
overflow-x: hidden !important;
|
||||
}
|
||||
|
||||
/* Ensure full width on mobile */
|
||||
.app {
|
||||
max-width: 100vw !important;
|
||||
}
|
||||
|
||||
/* Fix button overflow */
|
||||
button {
|
||||
max-width: 100%;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
/* Fix comment-meta URI overflow */
|
||||
.comment-meta {
|
||||
word-break: break-all !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
}
|
||||
|
||||
.gacha-section {
|
||||
|
@@ -3,7 +3,7 @@ import { OAuthCallback } from './components/OAuthCallback';
|
||||
import { AIChat } from './components/AIChat';
|
||||
import { authService, User } from './services/auth';
|
||||
import { atprotoOAuthService } from './services/atproto-oauth';
|
||||
import { appConfig } from './config/app';
|
||||
import { appConfig, getCollectionNames } from './config/app';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
@@ -46,8 +46,10 @@ function App() {
|
||||
const [isPostingUserList, setIsPostingUserList] = useState(false);
|
||||
const [userListRecords, setUserListRecords] = useState<any[]>([]);
|
||||
const [showJsonFor, setShowJsonFor] = useState<string | null>(null);
|
||||
const [activeTab, setActiveTab] = useState<'comments' | 'ai-chat'>('comments');
|
||||
const [activeTab, setActiveTab] = useState<'comments' | 'ai-chat' | 'lang-en' | 'ai-comment'>('comments');
|
||||
const [aiChatHistory, setAiChatHistory] = useState<any[]>([]);
|
||||
const [langEnRecords, setLangEnRecords] = useState<any[]>([]);
|
||||
const [aiCommentRecords, setAiCommentRecords] = useState<any[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
// Setup Jetstream WebSocket for real-time comments (optional)
|
||||
@@ -55,17 +57,18 @@ function App() {
|
||||
try {
|
||||
const ws = new WebSocket('wss://jetstream2.us-east.bsky.network/subscribe');
|
||||
|
||||
const collections = getCollectionNames(appConfig.collections.base);
|
||||
ws.onopen = () => {
|
||||
console.log('Jetstream connected');
|
||||
ws.send(JSON.stringify({
|
||||
wantedCollections: [appConfig.collections.comment]
|
||||
wantedCollections: [collections.comment]
|
||||
}));
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.collection === appConfig.collections.comment && data.commit?.operation === 'create') {
|
||||
if (data.collection === collections.comment && data.commit?.operation === 'create') {
|
||||
console.log('New comment detected via Jetstream:', data);
|
||||
// Optionally reload comments
|
||||
// loadAllComments(window.location.href);
|
||||
@@ -190,6 +193,9 @@ function App() {
|
||||
};
|
||||
|
||||
checkAuth();
|
||||
|
||||
// Load AI generated content (public)
|
||||
loadAIGeneratedContent();
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('popstate', handlePopState);
|
||||
@@ -274,6 +280,45 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
// Load AI generated content from admin DID
|
||||
const loadAIGeneratedContent = async () => {
|
||||
try {
|
||||
const adminDid = appConfig.adminDid;
|
||||
const bskyApi = appConfig.bskyPublicApi || 'https://public.api.bsky.app';
|
||||
const collections = getCollectionNames(appConfig.collections.base);
|
||||
|
||||
// Load lang:en records
|
||||
const langResponse = await fetch(`${bskyApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(collections.chatLang)}&limit=100`);
|
||||
if (langResponse.ok) {
|
||||
const langData = await langResponse.json();
|
||||
const langRecords = langData.records || [];
|
||||
|
||||
// Filter by current page URL if on post page
|
||||
const filteredLangRecords = appConfig.rkey
|
||||
? langRecords.filter(record => record.value.url === window.location.href)
|
||||
: langRecords.slice(0, 3); // Top page: latest 3
|
||||
|
||||
setLangEnRecords(filteredLangRecords);
|
||||
}
|
||||
|
||||
// Load AI comment records
|
||||
const commentResponse = await fetch(`${bskyApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(collections.chatComment)}&limit=100`);
|
||||
if (commentResponse.ok) {
|
||||
const commentData = await commentResponse.json();
|
||||
const commentRecords = commentData.records || [];
|
||||
|
||||
// Filter by current page URL if on post page
|
||||
const filteredCommentRecords = appConfig.rkey
|
||||
? commentRecords.filter(record => record.value.url === window.location.href)
|
||||
: commentRecords.slice(0, 3); // Top page: latest 3
|
||||
|
||||
setAiCommentRecords(filteredCommentRecords);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load AI generated content:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const loadUserComments = async (did: string) => {
|
||||
try {
|
||||
console.log('Loading comments for DID:', did);
|
||||
@@ -454,7 +499,8 @@ function App() {
|
||||
console.log(`Fetching comments from user: ${user.handle} (${user.did}) at ${user.pds}`);
|
||||
|
||||
// Public API使用(認証不要)
|
||||
const response = await fetch(`${user.pds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(user.did)}&collection=${encodeURIComponent(appConfig.collections.comment)}&limit=100`);
|
||||
const collections = getCollectionNames(appConfig.collections.base);
|
||||
const response = await fetch(`${user.pds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(user.did)}&collection=${encodeURIComponent(collections.comment)}&limit=100`);
|
||||
|
||||
if (!response.ok) {
|
||||
console.warn(`Failed to fetch from ${user.handle} (${response.status}): ${response.statusText}`);
|
||||
@@ -1043,14 +1089,23 @@ function App() {
|
||||
AI Chat History ({aiChatHistory.length})
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className={`tab-button ${activeTab === 'lang-en' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('lang-en')}
|
||||
>
|
||||
Lang: EN ({langEnRecords.length})
|
||||
</button>
|
||||
<button
|
||||
className={`tab-button ${activeTab === 'ai-comment' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('ai-comment')}
|
||||
>
|
||||
AI Comment ({aiCommentRecords.length})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Comments List */}
|
||||
{activeTab === 'comments' && (
|
||||
<div className="comments-list">
|
||||
<div className="comments-header">
|
||||
<h3>Comments</h3>
|
||||
</div>
|
||||
{comments.filter(shouldShowComment).length === 0 ? (
|
||||
<p className="no-comments">
|
||||
{appConfig.rkey ? `No comments for this post yet` : `No comments yet`}
|
||||
@@ -1120,7 +1175,9 @@ function App() {
|
||||
{record.value.text}
|
||||
</div>
|
||||
<div className="comment-meta">
|
||||
<small>{record.uri}</small>
|
||||
{record.value.url && (
|
||||
<small><a href={record.value.url}>{record.value.url}</a></small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* JSON Display */}
|
||||
@@ -1204,7 +1261,9 @@ function App() {
|
||||
{record.value.question || record.value.answer}
|
||||
</div>
|
||||
<div className="comment-meta">
|
||||
<small>{record.uri}</small>
|
||||
{record.value.url && (
|
||||
<small><a href={record.value.url}>{record.value.url}</a></small>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* JSON Display */}
|
||||
@@ -1222,6 +1281,88 @@ function App() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Lang: EN List */}
|
||||
{activeTab === 'lang-en' && (
|
||||
<div className="lang-en-list">
|
||||
{langEnRecords.length === 0 ? (
|
||||
<p className="no-content">No English translations yet</p>
|
||||
) : (
|
||||
langEnRecords.map((record, index) => (
|
||||
<div key={index} className="lang-item">
|
||||
<div className="lang-header">
|
||||
<img
|
||||
src={record.value.author?.avatar || generatePlaceholderAvatar(record.value.author?.handle || 'AI')}
|
||||
alt="AI Avatar"
|
||||
className="comment-avatar"
|
||||
/>
|
||||
<div className="comment-author-info">
|
||||
<span className="comment-author">
|
||||
{record.value.author?.displayName || 'AI Translator'}
|
||||
</span>
|
||||
<span className="comment-handle">
|
||||
@{record.value.author?.handle || 'ai'}
|
||||
</span>
|
||||
</div>
|
||||
<span className="comment-date">
|
||||
{new Date(record.value.createdAt).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="lang-content">
|
||||
<div className="lang-type">Type: {record.value.type || 'en'}</div>
|
||||
<div className="lang-body">{record.value.body}</div>
|
||||
</div>
|
||||
<div className="comment-meta">
|
||||
{record.value.url && (
|
||||
<small><a href={record.value.url}>{record.value.url}</a></small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* AI Comment List */}
|
||||
{activeTab === 'ai-comment' && (
|
||||
<div className="ai-comment-list">
|
||||
{aiCommentRecords.length === 0 ? (
|
||||
<p className="no-content">No AI comments yet</p>
|
||||
) : (
|
||||
aiCommentRecords.map((record, index) => (
|
||||
<div key={index} className="ai-comment-item">
|
||||
<div className="ai-comment-header">
|
||||
<img
|
||||
src={record.value.author?.avatar || generatePlaceholderAvatar(record.value.author?.handle || 'AI')}
|
||||
alt="AI Avatar"
|
||||
className="comment-avatar"
|
||||
/>
|
||||
<div className="comment-author-info">
|
||||
<span className="comment-author">
|
||||
{record.value.author?.displayName || 'AI Commenter'}
|
||||
</span>
|
||||
<span className="comment-handle">
|
||||
@{record.value.author?.handle || 'ai'}
|
||||
</span>
|
||||
</div>
|
||||
<span className="comment-date">
|
||||
{new Date(record.value.createdAt).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="ai-comment-content">
|
||||
<div className="ai-comment-type">Type: {record.value.type || 'comment'}</div>
|
||||
<div className="ai-comment-body">{record.value.body}</div>
|
||||
</div>
|
||||
<div className="comment-meta">
|
||||
{record.value.url && (
|
||||
<small><a href={record.value.url}>{record.value.url}</a></small>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Comment Form - Only show on post pages */}
|
||||
{user && appConfig.rkey && (
|
||||
<div className="comment-form">
|
||||
|
@@ -2,9 +2,7 @@
|
||||
export interface AppConfig {
|
||||
adminDid: string;
|
||||
collections: {
|
||||
comment: string;
|
||||
user: string;
|
||||
chat: string;
|
||||
base: string; // Base collection like "ai.syui.log"
|
||||
};
|
||||
host: string;
|
||||
rkey?: string; // Current post rkey if on post page
|
||||
@@ -16,10 +14,21 @@ export interface AppConfig {
|
||||
bskyPublicApi: string;
|
||||
}
|
||||
|
||||
// Collection name builders (similar to Rust implementation)
|
||||
export function getCollectionNames(base: string) {
|
||||
return {
|
||||
comment: base,
|
||||
user: `${base}.user`,
|
||||
chat: `${base}.chat`,
|
||||
chatLang: `${base}.chat.lang`,
|
||||
chatComment: `${base}.chat.comment`,
|
||||
};
|
||||
}
|
||||
|
||||
// Generate collection names from host
|
||||
// Format: ${reg}.${name}.${sub}
|
||||
// Example: log.syui.ai -> ai.syui.log
|
||||
function generateCollectionNames(host: string): { comment: string; user: string; chat: string } {
|
||||
function generateBaseCollectionFromHost(host: string): string {
|
||||
try {
|
||||
// Remove protocol if present
|
||||
const cleanHost = host.replace(/^https?:\/\//, '');
|
||||
@@ -34,29 +43,19 @@ function generateCollectionNames(host: string): { comment: string; user: string;
|
||||
// Reverse the parts for collection naming
|
||||
// log.syui.ai -> ai.syui.log
|
||||
const reversedParts = parts.reverse();
|
||||
const collectionBase = reversedParts.join('.');
|
||||
|
||||
return {
|
||||
comment: collectionBase,
|
||||
user: `${collectionBase}.user`,
|
||||
chat: `${collectionBase}.chat`
|
||||
};
|
||||
return reversedParts.join('.');
|
||||
} catch (error) {
|
||||
console.warn('Failed to generate collection names from host:', host, error);
|
||||
// Fallback to default collections
|
||||
return {
|
||||
comment: 'ai.syui.log',
|
||||
user: 'ai.syui.log.user',
|
||||
chat: 'ai.syui.log.chat'
|
||||
};
|
||||
console.warn('Failed to generate collection base from host:', host, error);
|
||||
// Fallback to default
|
||||
return 'ai.syui.log';
|
||||
}
|
||||
}
|
||||
|
||||
// Extract rkey from current URL
|
||||
// /posts/xxx.html -> xxx
|
||||
// /posts/xxx -> xxx
|
||||
function extractRkeyFromUrl(): string | undefined {
|
||||
const pathname = window.location.pathname;
|
||||
const match = pathname.match(/\/posts\/([^/]+)\.html$/);
|
||||
const match = pathname.match(/\/posts\/([^/]+)\/?$/);
|
||||
return match ? match[1] : undefined;
|
||||
}
|
||||
|
||||
@@ -66,11 +65,9 @@ export function getAppConfig(): AppConfig {
|
||||
const adminDid = import.meta.env.VITE_ADMIN_DID || 'did:plc:uqzpqmrjnptsxezjx4xuh2mn';
|
||||
|
||||
// Priority: Environment variables > Auto-generated from host
|
||||
const autoGeneratedCollections = generateCollectionNames(host);
|
||||
const autoGeneratedBase = generateBaseCollectionFromHost(host);
|
||||
const collections = {
|
||||
comment: import.meta.env.VITE_COLLECTION_COMMENT || autoGeneratedCollections.comment,
|
||||
user: import.meta.env.VITE_COLLECTION_USER || autoGeneratedCollections.user,
|
||||
chat: import.meta.env.VITE_COLLECTION_CHAT || autoGeneratedCollections.chat,
|
||||
base: import.meta.env.VITE_OAUTH_COLLECTION || autoGeneratedBase,
|
||||
};
|
||||
|
||||
const rkey = extractRkeyFromUrl();
|
||||
|
@@ -28,8 +28,31 @@ pub struct JetstreamConfig {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CollectionConfig {
|
||||
pub comment: String,
|
||||
pub user: String,
|
||||
pub base: String, // Base collection name like "ai.syui.log"
|
||||
}
|
||||
|
||||
impl CollectionConfig {
|
||||
// Collection name builders
|
||||
pub fn comment(&self) -> String {
|
||||
self.base.clone()
|
||||
}
|
||||
|
||||
pub fn user(&self) -> String {
|
||||
format!("{}.user", self.base)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn chat(&self) -> String {
|
||||
format!("{}.chat", self.base)
|
||||
}
|
||||
|
||||
pub fn chat_lang(&self) -> String {
|
||||
format!("{}.chat.lang", self.base)
|
||||
}
|
||||
|
||||
pub fn chat_comment(&self) -> String {
|
||||
format!("{}.chat.comment", self.base)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AuthConfig {
|
||||
@@ -47,8 +70,7 @@ impl Default for AuthConfig {
|
||||
collections: vec!["ai.syui.log".to_string()],
|
||||
},
|
||||
collections: CollectionConfig {
|
||||
comment: "ai.syui.log".to_string(),
|
||||
user: "ai.syui.log.user".to_string(),
|
||||
base: "ai.syui.log".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -220,11 +242,50 @@ pub fn load_config() -> Result<AuthConfig> {
|
||||
}
|
||||
|
||||
let config_json = fs::read_to_string(&config_path)?;
|
||||
let mut config: AuthConfig = serde_json::from_str(&config_json)?;
|
||||
|
||||
// Update collection configuration
|
||||
// Try to load as new format first, then migrate if needed
|
||||
match serde_json::from_str::<AuthConfig>(&config_json) {
|
||||
Ok(mut config) => {
|
||||
// Update collection configuration
|
||||
update_config_collections(&mut config);
|
||||
Ok(config)
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", format!("Parse error: {}, attempting migration...", e).yellow());
|
||||
// Try to migrate from old format
|
||||
migrate_config_if_needed(&config_path, &config_json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_config_if_needed(config_path: &std::path::Path, config_json: &str) -> Result<AuthConfig> {
|
||||
// Try to parse as old format and migrate to new simple format
|
||||
let mut old_config: serde_json::Value = serde_json::from_str(config_json)?;
|
||||
|
||||
// Migrate old collections structure to new base-only structure
|
||||
if let Some(collections) = old_config.get_mut("collections") {
|
||||
// Extract base collection name from comment field or use default
|
||||
let base_collection = collections.get("comment")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log")
|
||||
.to_string();
|
||||
|
||||
// Replace entire collections structure with new format
|
||||
old_config["collections"] = serde_json::json!({
|
||||
"base": base_collection
|
||||
});
|
||||
}
|
||||
|
||||
// Save migrated config
|
||||
let migrated_config_json = serde_json::to_string_pretty(&old_config)?;
|
||||
fs::write(config_path, migrated_config_json)?;
|
||||
|
||||
// Parse as new format
|
||||
let mut config: AuthConfig = serde_json::from_value(old_config)?;
|
||||
update_config_collections(&mut config);
|
||||
|
||||
println!("{}", "✅ Configuration migrated to new simplified format".green());
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
@@ -259,7 +320,7 @@ async fn test_api_access_with_auth(config: &AuthConfig) -> Result<()> {
|
||||
let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=1",
|
||||
config.admin.pds,
|
||||
urlencoding::encode(&config.admin.did),
|
||||
urlencoding::encode(&config.collections.comment));
|
||||
urlencoding::encode(&config.collections.comment()));
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
@@ -311,23 +372,14 @@ fn save_config(config: &AuthConfig) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Generate collection names from admin DID or environment
|
||||
// Generate collection config from environment
|
||||
fn generate_collection_config() -> CollectionConfig {
|
||||
// Check environment variables first
|
||||
if let (Ok(comment), Ok(user)) = (
|
||||
std::env::var("AILOG_COLLECTION_COMMENT"),
|
||||
std::env::var("AILOG_COLLECTION_USER")
|
||||
) {
|
||||
return CollectionConfig {
|
||||
comment,
|
||||
user,
|
||||
};
|
||||
}
|
||||
// Use VITE_OAUTH_COLLECTION for unified configuration
|
||||
let base = std::env::var("VITE_OAUTH_COLLECTION")
|
||||
.unwrap_or_else(|_| "ai.syui.log".to_string());
|
||||
|
||||
// Default collections
|
||||
CollectionConfig {
|
||||
comment: "ai.syui.log".to_string(),
|
||||
user: "ai.syui.log.user".to_string(),
|
||||
base,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,5 +387,5 @@ fn generate_collection_config() -> CollectionConfig {
|
||||
pub fn update_config_collections(config: &mut AuthConfig) {
|
||||
config.collections = generate_collection_config();
|
||||
// Also update jetstream collections to monitor the comment collection
|
||||
config.jetstream.collections = vec![config.collections.comment.clone()];
|
||||
config.jetstream.collections = vec![config.collections.comment()];
|
||||
}
|
@@ -45,18 +45,10 @@ pub async fn build(project_dir: PathBuf) -> Result<()> {
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| anyhow::anyhow!("No admin DID found in [oauth] section"))?;
|
||||
|
||||
let collection_comment = oauth_config.get("collection_comment")
|
||||
let collection_base = oauth_config.get("collection")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log");
|
||||
|
||||
let collection_user = oauth_config.get("collection_user")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log.user");
|
||||
|
||||
let collection_chat = oauth_config.get("collection_chat")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log.chat");
|
||||
|
||||
// Extract AI config if present
|
||||
let ai_config = config.get("ai")
|
||||
.and_then(|v| v.as_table());
|
||||
@@ -109,15 +101,8 @@ VITE_OAUTH_CLIENT_ID={}/{}
|
||||
VITE_OAUTH_REDIRECT_URI={}/{}
|
||||
VITE_ADMIN_DID={}
|
||||
|
||||
# Collection names for OAuth app
|
||||
VITE_COLLECTION_COMMENT={}
|
||||
VITE_COLLECTION_USER={}
|
||||
VITE_COLLECTION_CHAT={}
|
||||
|
||||
# Collection names for ailog (backward compatibility)
|
||||
AILOG_COLLECTION_COMMENT={}
|
||||
AILOG_COLLECTION_USER={}
|
||||
AILOG_COLLECTION_CHAT={}
|
||||
# Base collection for OAuth app and ailog (all others are derived)
|
||||
VITE_OAUTH_COLLECTION={}
|
||||
|
||||
# AI Configuration
|
||||
VITE_AI_ENABLED={}
|
||||
@@ -135,12 +120,7 @@ VITE_BSKY_PUBLIC_API={}
|
||||
base_url, client_id_path,
|
||||
base_url, redirect_path,
|
||||
admin_did,
|
||||
collection_comment,
|
||||
collection_user,
|
||||
collection_chat,
|
||||
collection_comment,
|
||||
collection_user,
|
||||
collection_chat,
|
||||
collection_base,
|
||||
ai_enabled,
|
||||
ai_ask_ai,
|
||||
ai_provider,
|
||||
|
@@ -10,18 +10,58 @@ use std::process::{Command, Stdio};
|
||||
use tokio::time::{sleep, Duration, interval};
|
||||
use tokio_tungstenite::{connect_async, tungstenite::Message};
|
||||
use toml;
|
||||
use reqwest;
|
||||
|
||||
use super::auth::{load_config, load_config_with_refresh, AuthConfig};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
struct BlogPost {
|
||||
title: String,
|
||||
href: String,
|
||||
#[serde(rename = "formated_time")]
|
||||
#[allow(dead_code)]
|
||||
date: String,
|
||||
#[allow(dead_code)]
|
||||
tags: Vec<String>,
|
||||
#[allow(dead_code)]
|
||||
contents: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
struct BlogIndex {
|
||||
#[allow(dead_code)]
|
||||
posts: Vec<BlogPost>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct OllamaRequest {
|
||||
model: String,
|
||||
prompt: String,
|
||||
stream: bool,
|
||||
options: OllamaOptions,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct OllamaOptions {
|
||||
temperature: f32,
|
||||
top_p: f32,
|
||||
num_predict: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct OllamaResponse {
|
||||
response: String,
|
||||
}
|
||||
|
||||
// Load collection config with priority: env vars > project config.toml > defaults
|
||||
fn load_collection_config(project_dir: Option<&Path>) -> Result<(String, String)> {
|
||||
// 1. Check environment variables first (highest priority)
|
||||
if let (Ok(comment), Ok(user)) = (
|
||||
std::env::var("AILOG_COLLECTION_COMMENT"),
|
||||
std::env::var("AILOG_COLLECTION_USER")
|
||||
) {
|
||||
if let Ok(base_collection) = std::env::var("VITE_OAUTH_COLLECTION") {
|
||||
println!("{}", "📂 Using collection config from environment variables".cyan());
|
||||
return Ok((comment, user));
|
||||
let collection_user = format!("{}.user", base_collection);
|
||||
return Ok((base_collection, collection_user));
|
||||
}
|
||||
|
||||
// 2. Try to load from project config.toml (second priority)
|
||||
@@ -60,17 +100,16 @@ fn load_collection_config_from_project(project_dir: &Path) -> Result<(String, St
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| anyhow::anyhow!("No [oauth] section found in config.toml"))?;
|
||||
|
||||
let collection_comment = oauth_config.get("collection_comment")
|
||||
// Use new simplified collection structure (base collection)
|
||||
let collection_base = oauth_config.get("collection")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log")
|
||||
.to_string();
|
||||
|
||||
let collection_user = oauth_config.get("collection_user")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("ai.syui.log.user")
|
||||
.to_string();
|
||||
// Derive user collection from base
|
||||
let collection_user = format!("{}.user", collection_base);
|
||||
|
||||
Ok((collection_comment, collection_user))
|
||||
Ok((collection_base, collection_user))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -118,15 +157,14 @@ fn get_pid_file() -> Result<PathBuf> {
|
||||
Ok(pid_dir.join("stream.pid"))
|
||||
}
|
||||
|
||||
pub async fn start(project_dir: Option<PathBuf>, daemon: bool) -> Result<()> {
|
||||
pub async fn start(project_dir: Option<PathBuf>, daemon: bool, ai_generate: bool) -> Result<()> {
|
||||
let mut config = load_config_with_refresh().await?;
|
||||
|
||||
// Load collection config with priority: env vars > project config > defaults
|
||||
let (collection_comment, collection_user) = load_collection_config(project_dir.as_deref())?;
|
||||
let (collection_comment, _collection_user) = load_collection_config(project_dir.as_deref())?;
|
||||
|
||||
// Update config with loaded collections
|
||||
config.collections.comment = collection_comment.clone();
|
||||
config.collections.user = collection_user;
|
||||
config.collections.base = collection_comment.clone();
|
||||
config.jetstream.collections = vec![collection_comment];
|
||||
|
||||
let pid_file = get_pid_file()?;
|
||||
@@ -151,6 +189,11 @@ pub async fn start(project_dir: Option<PathBuf>, daemon: bool) -> Result<()> {
|
||||
args.push(project_path.to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
// Add ai_generate flag if enabled
|
||||
if ai_generate {
|
||||
args.push("--ai-generate".to_string());
|
||||
}
|
||||
|
||||
let child = Command::new(current_exe)
|
||||
.args(&args)
|
||||
.stdin(Stdio::null())
|
||||
@@ -192,6 +235,19 @@ pub async fn start(project_dir: Option<PathBuf>, daemon: bool) -> Result<()> {
|
||||
let max_reconnect_attempts = 10;
|
||||
let mut config = config; // Make config mutable for token refresh
|
||||
|
||||
// Start AI generation monitor if enabled
|
||||
if ai_generate {
|
||||
let ai_config = config.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
if let Err(e) = run_ai_generation_monitor(&ai_config).await {
|
||||
println!("{}", format!("❌ AI generation monitor error: {}", e).red());
|
||||
sleep(Duration::from_secs(60)).await; // Wait 1 minute before retry
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loop {
|
||||
match run_monitor(&mut config).await {
|
||||
Ok(_) => {
|
||||
@@ -344,7 +400,7 @@ async fn handle_message(text: &str, config: &mut AuthConfig) -> Result<()> {
|
||||
if let (Some(collection), Some(commit), Some(did)) =
|
||||
(&message.collection, &message.commit, &message.did) {
|
||||
|
||||
if collection == &config.collections.comment && commit.operation.as_deref() == Some("create") {
|
||||
if collection == &config.collections.comment() && commit.operation.as_deref() == Some("create") {
|
||||
let unknown_uri = "unknown".to_string();
|
||||
let uri = commit.uri.as_ref().unwrap_or(&unknown_uri);
|
||||
|
||||
@@ -438,7 +494,7 @@ async fn get_current_user_list(config: &mut AuthConfig) -> Result<Vec<UserRecord
|
||||
let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=10",
|
||||
config.admin.pds,
|
||||
urlencoding::encode(&config.admin.did),
|
||||
urlencoding::encode(&config.collections.user));
|
||||
urlencoding::encode(&config.collections.user()));
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
@@ -501,7 +557,7 @@ async fn post_user_list(config: &mut AuthConfig, users: &[UserRecord], metadata:
|
||||
let rkey = format!("{}-{}", short_did, now.format("%Y-%m-%dT%H-%M-%S-%3fZ").to_string().replace(".", "-"));
|
||||
|
||||
let record = UserListRecord {
|
||||
record_type: config.collections.user.clone(),
|
||||
record_type: config.collections.user(),
|
||||
users: users.to_vec(),
|
||||
created_at: now.to_rfc3339(),
|
||||
updated_by: UserInfo {
|
||||
@@ -515,7 +571,7 @@ async fn post_user_list(config: &mut AuthConfig, users: &[UserRecord], metadata:
|
||||
|
||||
let request_body = json!({
|
||||
"repo": config.admin.did,
|
||||
"collection": config.collections.user,
|
||||
"collection": config.collections.user(),
|
||||
"rkey": rkey,
|
||||
"record": record
|
||||
});
|
||||
@@ -759,7 +815,7 @@ async fn get_recent_comments(config: &mut AuthConfig) -> Result<Vec<Value>> {
|
||||
let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=20",
|
||||
config.admin.pds,
|
||||
urlencoding::encode(&config.admin.did),
|
||||
urlencoding::encode(&config.collections.comment));
|
||||
urlencoding::encode(&config.collections.comment()));
|
||||
|
||||
if std::env::var("AILOG_DEBUG").is_ok() {
|
||||
println!("{}", format!("🌐 API Request URL: {}", url).yellow());
|
||||
@@ -840,7 +896,7 @@ pub async fn test_api() -> Result<()> {
|
||||
println!("{}", format!("✅ Successfully retrieved {} comments", comments.len()).green());
|
||||
|
||||
if comments.is_empty() {
|
||||
println!("{}", format!("ℹ️ No comments found in {} collection", config.collections.comment).blue());
|
||||
println!("{}", format!("ℹ️ No comments found in {} collection", config.collections.comment()).blue());
|
||||
println!("💡 Try posting a comment first using the web interface");
|
||||
} else {
|
||||
println!("{}", "📝 Comment details:".cyan());
|
||||
@@ -871,5 +927,273 @@ pub async fn test_api() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// AI content generation functions
|
||||
async fn generate_ai_content(content: &str, prompt_type: &str, ollama_host: &str) -> Result<String> {
|
||||
let model = "gemma3:4b";
|
||||
|
||||
let prompt = match prompt_type {
|
||||
"translate" => format!("Translate the following Japanese blog post to English. Keep the technical terms and code blocks intact:\n\n{}", content),
|
||||
"comment" => format!("Read this blog post and provide an insightful comment about it. Focus on the key points and add your perspective:\n\n{}", content),
|
||||
_ => return Err(anyhow::anyhow!("Unknown prompt type: {}", prompt_type)),
|
||||
};
|
||||
|
||||
let request = OllamaRequest {
|
||||
model: model.to_string(),
|
||||
prompt,
|
||||
stream: false,
|
||||
options: OllamaOptions {
|
||||
temperature: 0.9,
|
||||
top_p: 0.9,
|
||||
num_predict: 500,
|
||||
},
|
||||
};
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
// Try localhost first (for same-server deployment)
|
||||
let localhost_url = "http://localhost:11434/api/generate";
|
||||
match client.post(localhost_url).json(&request).send().await {
|
||||
Ok(response) if response.status().is_success() => {
|
||||
let ollama_response: OllamaResponse = response.json().await?;
|
||||
println!("{}", "✅ Used localhost Ollama".green());
|
||||
return Ok(ollama_response.response);
|
||||
}
|
||||
_ => {
|
||||
println!("{}", "⚠️ Localhost Ollama not available, trying remote...".yellow());
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to remote host
|
||||
let remote_url = format!("{}/api/generate", ollama_host);
|
||||
let response = client.post(&remote_url).json(&request).send().await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow::anyhow!("Ollama API request failed: {}", response.status()));
|
||||
}
|
||||
|
||||
let ollama_response: OllamaResponse = response.json().await?;
|
||||
println!("{}", "✅ Used remote Ollama".green());
|
||||
Ok(ollama_response.response)
|
||||
}
|
||||
|
||||
async fn run_ai_generation_monitor(config: &AuthConfig) -> Result<()> {
|
||||
let blog_host = "https://syui.ai"; // TODO: Load from config
|
||||
let ollama_host = "https://ollama.syui.ai"; // TODO: Load from config
|
||||
let ai_did = "did:plc:4hqjfn7m6n5hno3doamuhgef"; // TODO: Load from config
|
||||
|
||||
println!("{}", "🤖 Starting AI content generation monitor...".cyan());
|
||||
println!("📡 Blog host: {}", blog_host);
|
||||
println!("🧠 Ollama host: {}", ollama_host);
|
||||
println!("🤖 AI DID: {}", ai_did);
|
||||
println!();
|
||||
|
||||
let mut interval = interval(Duration::from_secs(300)); // Check every 5 minutes
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
println!("{}", "🔍 Checking for new blog posts...".blue());
|
||||
|
||||
match check_and_process_new_posts(&client, config, blog_host, ollama_host, ai_did).await {
|
||||
Ok(count) => {
|
||||
if count > 0 {
|
||||
println!("{}", format!("✅ Processed {} new posts", count).green());
|
||||
} else {
|
||||
println!("{}", "ℹ️ No new posts found".blue());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", format!("❌ Error processing posts: {}", e).red());
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", "⏰ Waiting for next check...".cyan());
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_and_process_new_posts(
|
||||
client: &reqwest::Client,
|
||||
config: &AuthConfig,
|
||||
blog_host: &str,
|
||||
ollama_host: &str,
|
||||
ai_did: &str,
|
||||
) -> Result<usize> {
|
||||
// Fetch blog index
|
||||
let index_url = format!("{}/index.json", blog_host);
|
||||
let response = client.get(&index_url).send().await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow::anyhow!("Failed to fetch blog index: {}", response.status()));
|
||||
}
|
||||
|
||||
let blog_posts: Vec<BlogPost> = response.json().await?;
|
||||
println!("{}", format!("📄 Found {} posts in blog index", blog_posts.len()).cyan());
|
||||
|
||||
// Get existing AI generated content from collections
|
||||
let existing_lang_records = get_existing_records(config, &config.collections.chat_lang()).await?;
|
||||
let existing_comment_records = get_existing_records(config, &config.collections.chat_comment()).await?;
|
||||
|
||||
let mut processed_count = 0;
|
||||
|
||||
for post in blog_posts {
|
||||
let post_slug = extract_slug_from_url(&post.href);
|
||||
|
||||
// Check if translation already exists
|
||||
let translation_exists = existing_lang_records.iter().any(|record| {
|
||||
record.get("value")
|
||||
.and_then(|v| v.get("post_slug"))
|
||||
.and_then(|s| s.as_str())
|
||||
== Some(&post_slug)
|
||||
});
|
||||
|
||||
// Check if comment already exists
|
||||
let comment_exists = existing_comment_records.iter().any(|record| {
|
||||
record.get("value")
|
||||
.and_then(|v| v.get("post_slug"))
|
||||
.and_then(|s| s.as_str())
|
||||
== Some(&post_slug)
|
||||
});
|
||||
|
||||
// Generate translation if not exists
|
||||
if !translation_exists {
|
||||
match generate_and_store_translation(client, config, &post, ollama_host, ai_did).await {
|
||||
Ok(_) => {
|
||||
println!("{}", format!("✅ Generated translation for: {}", post.title).green());
|
||||
processed_count += 1;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", format!("❌ Failed to generate translation for {}: {}", post.title, e).red());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate comment if not exists
|
||||
if !comment_exists {
|
||||
match generate_and_store_comment(client, config, &post, ollama_host, ai_did).await {
|
||||
Ok(_) => {
|
||||
println!("{}", format!("✅ Generated comment for: {}", post.title).green());
|
||||
processed_count += 1;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", format!("❌ Failed to generate comment for {}: {}", post.title, e).red());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(processed_count)
|
||||
}
|
||||
|
||||
async fn get_existing_records(config: &AuthConfig, collection: &str) -> Result<Vec<serde_json::Value>> {
|
||||
let client = reqwest::Client::new();
|
||||
let url = format!("{}/xrpc/com.atproto.repo.listRecords?repo={}&collection={}&limit=100",
|
||||
config.admin.pds,
|
||||
urlencoding::encode(&config.admin.did),
|
||||
urlencoding::encode(collection));
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
.header("Authorization", format!("Bearer {}", config.admin.access_jwt))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Ok(Vec::new()); // Return empty if collection doesn't exist yet
|
||||
}
|
||||
|
||||
let list_response: serde_json::Value = response.json().await?;
|
||||
let records = list_response["records"].as_array().unwrap_or(&Vec::new()).clone();
|
||||
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
fn extract_slug_from_url(url: &str) -> String {
|
||||
// Extract slug from URL like "/posts/2025-06-06-ailog.html"
|
||||
url.split('/')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.trim_end_matches(".html")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
async fn generate_and_store_translation(
|
||||
client: &reqwest::Client,
|
||||
config: &AuthConfig,
|
||||
post: &BlogPost,
|
||||
ollama_host: &str,
|
||||
ai_did: &str,
|
||||
) -> Result<()> {
|
||||
// Generate translation
|
||||
let translation = generate_ai_content(&post.title, "translate", ollama_host).await?;
|
||||
|
||||
// Store in ai.syui.log.chat.lang collection
|
||||
let record_data = serde_json::json!({
|
||||
"post_slug": extract_slug_from_url(&post.href),
|
||||
"post_title": post.title,
|
||||
"post_url": post.href,
|
||||
"lang": "en",
|
||||
"content": translation,
|
||||
"generated_at": chrono::Utc::now().to_rfc3339(),
|
||||
"ai_did": ai_did
|
||||
});
|
||||
|
||||
store_atproto_record(client, config, &config.collections.chat_lang(), &record_data).await
|
||||
}
|
||||
|
||||
async fn generate_and_store_comment(
|
||||
client: &reqwest::Client,
|
||||
config: &AuthConfig,
|
||||
post: &BlogPost,
|
||||
ollama_host: &str,
|
||||
ai_did: &str,
|
||||
) -> Result<()> {
|
||||
// Generate comment
|
||||
let comment = generate_ai_content(&post.title, "comment", ollama_host).await?;
|
||||
|
||||
// Store in ai.syui.log.chat.comment collection
|
||||
let record_data = serde_json::json!({
|
||||
"post_slug": extract_slug_from_url(&post.href),
|
||||
"post_title": post.title,
|
||||
"post_url": post.href,
|
||||
"content": comment,
|
||||
"generated_at": chrono::Utc::now().to_rfc3339(),
|
||||
"ai_did": ai_did
|
||||
});
|
||||
|
||||
store_atproto_record(client, config, &config.collections.chat_comment(), &record_data).await
|
||||
}
|
||||
|
||||
async fn store_atproto_record(
|
||||
client: &reqwest::Client,
|
||||
config: &AuthConfig,
|
||||
collection: &str,
|
||||
record_data: &serde_json::Value,
|
||||
) -> Result<()> {
|
||||
let url = format!("{}/xrpc/com.atproto.repo.putRecord", config.admin.pds);
|
||||
|
||||
let put_request = serde_json::json!({
|
||||
"repo": config.admin.did,
|
||||
"collection": collection,
|
||||
"rkey": uuid::Uuid::new_v4().to_string(),
|
||||
"record": record_data
|
||||
});
|
||||
|
||||
let response = client
|
||||
.post(&url)
|
||||
.header("Authorization", format!("Bearer {}", config.admin.access_jwt))
|
||||
.header("Content-Type", "application/json")
|
||||
.json(&put_request)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let error_text = response.text().await?;
|
||||
return Err(anyhow::anyhow!("Failed to store record: {}", error_text));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@@ -71,6 +71,9 @@ impl Generator {
|
||||
// Generate index page
|
||||
self.generate_index(&posts).await?;
|
||||
|
||||
// Generate JSON index for API access
|
||||
self.generate_json_index(&posts).await?;
|
||||
|
||||
// Generate post pages
|
||||
for post in &posts {
|
||||
self.generate_post_page(post).await?;
|
||||
@@ -446,6 +449,63 @@ impl Generator {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn generate_json_index(&self, posts: &[Post]) -> Result<()> {
|
||||
let index_data: Vec<serde_json::Value> = posts.iter().map(|post| {
|
||||
// Parse date for proper formatting
|
||||
let parsed_date = chrono::NaiveDate::parse_from_str(&post.date, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| chrono::Utc::now().naive_utc().date());
|
||||
|
||||
// Format to Hugo-style date format (Mon Jan 2, 2006)
|
||||
let formatted_date = parsed_date.format("%a %b %-d, %Y").to_string();
|
||||
|
||||
// Create UTC datetime for utc_time field
|
||||
let utc_datetime = parsed_date.and_hms_opt(0, 0, 0)
|
||||
.unwrap_or_else(|| chrono::Utc::now().naive_utc());
|
||||
let utc_time = format!("{}Z", utc_datetime.format("%Y-%m-%dT%H:%M:%S"));
|
||||
|
||||
// Extract plain text content from HTML
|
||||
let contents = self.extract_plain_text(&post.content);
|
||||
|
||||
serde_json::json!({
|
||||
"title": post.title,
|
||||
"tags": post.tags,
|
||||
"description": self.extract_excerpt(&post.content),
|
||||
"categories": [],
|
||||
"contents": contents,
|
||||
"href": format!("{}{}", self.config.site.base_url.trim_end_matches('/'), post.url),
|
||||
"utc_time": utc_time,
|
||||
"formated_time": formatted_date
|
||||
})
|
||||
}).collect();
|
||||
|
||||
// Write JSON index to public directory
|
||||
let output_path = self.base_path.join("public/index.json");
|
||||
let json_content = serde_json::to_string_pretty(&index_data)?;
|
||||
fs::write(output_path, json_content)?;
|
||||
|
||||
println!("{} JSON index with {} posts", "Generated".cyan(), posts.len());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn extract_plain_text(&self, html_content: &str) -> String {
|
||||
// Remove HTML tags and extract plain text
|
||||
let mut text = String::new();
|
||||
let mut in_tag = false;
|
||||
|
||||
for ch in html_content.chars() {
|
||||
match ch {
|
||||
'<' => in_tag = true,
|
||||
'>' => in_tag = false,
|
||||
_ if !in_tag => text.push(ch),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up whitespace
|
||||
text.split_whitespace().collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
@@ -479,4 +539,19 @@ pub struct Translation {
|
||||
pub title: String,
|
||||
pub content: String,
|
||||
pub url: String,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[allow(dead_code)]
|
||||
struct BlogPost {
|
||||
title: String,
|
||||
url: String,
|
||||
date: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[allow(dead_code)]
|
||||
struct BlogIndex {
|
||||
posts: Vec<BlogPost>,
|
||||
}
|
||||
|
||||
|
28
src/main.rs
28
src/main.rs
@@ -18,10 +18,14 @@ mod mcp;
|
||||
#[derive(Parser)]
|
||||
#[command(name = "ailog")]
|
||||
#[command(about = "A static blog generator with AI features")]
|
||||
#[command(version)]
|
||||
#[command(disable_version_flag = true)]
|
||||
struct Cli {
|
||||
/// Print version information
|
||||
#[arg(short = 'V', long = "version")]
|
||||
version: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -114,6 +118,9 @@ enum StreamCommands {
|
||||
/// Run as daemon
|
||||
#[arg(short, long)]
|
||||
daemon: bool,
|
||||
/// Enable AI content generation
|
||||
#[arg(long)]
|
||||
ai_generate: bool,
|
||||
},
|
||||
/// Stop monitoring
|
||||
Stop,
|
||||
@@ -135,8 +142,19 @@ enum OauthCommands {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// Handle version flag
|
||||
if cli.version {
|
||||
println!("{}", env!("CARGO_PKG_VERSION"));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Require subcommand if no version flag
|
||||
let command = cli.command.ok_or_else(|| {
|
||||
anyhow::anyhow!("No subcommand provided. Use --help for usage information.")
|
||||
})?;
|
||||
|
||||
match cli.command {
|
||||
match command {
|
||||
Commands::Init { path } => {
|
||||
commands::init::execute(path).await?;
|
||||
}
|
||||
@@ -178,8 +196,8 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
Commands::Stream { command } => {
|
||||
match command {
|
||||
StreamCommands::Start { project_dir, daemon } => {
|
||||
commands::stream::start(project_dir, daemon).await?;
|
||||
StreamCommands::Start { project_dir, daemon, ai_generate } => {
|
||||
commands::stream::start(project_dir, daemon, ai_generate).await?;
|
||||
}
|
||||
StreamCommands::Stop => {
|
||||
commands::stream::stop().await?;
|
||||
|
Reference in New Issue
Block a user