Compare commits
4 Commits
0d79af5aa5
...
v0.1.6
Author | SHA1 | Date | |
---|---|---|---|
5d97576544
|
|||
d16b88a499
|
|||
4df7f72312
|
|||
af28cefba0
|
@@ -48,11 +48,7 @@
|
|||||||
"Bash(git tag:*)",
|
"Bash(git tag:*)",
|
||||||
"Bash(../bin/ailog:*)",
|
"Bash(../bin/ailog:*)",
|
||||||
"Bash(../target/release/ailog oauth build:*)",
|
"Bash(../target/release/ailog oauth build:*)",
|
||||||
"Bash(ailog:*)",
|
"Bash(ailog:*)"
|
||||||
"WebFetch(domain:plc.directory)",
|
|
||||||
"WebFetch(domain:atproto.com)",
|
|
||||||
"WebFetch(domain:syu.is)",
|
|
||||||
"Bash(sed:*)"
|
|
||||||
],
|
],
|
||||||
"deny": []
|
"deny": []
|
||||||
}
|
}
|
||||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.swo
|
*.swo
|
||||||
*~
|
*~
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
cloudflare-config.yml
|
||||||
my-blog/public/
|
my-blog/public/
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
@@ -12,8 +13,3 @@ package-lock.json
|
|||||||
my-blog/static/assets/comment-atproto-*
|
my-blog/static/assets/comment-atproto-*
|
||||||
bin/ailog
|
bin/ailog
|
||||||
docs
|
docs
|
||||||
my-blog/static/index.html
|
|
||||||
my-blog/templates/oauth-assets.html
|
|
||||||
cloudflared-config.yml
|
|
||||||
.config
|
|
||||||
oauth-server-example
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ailog"
|
name = "ailog"
|
||||||
version = "0.2.0"
|
version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["syui"]
|
authors = ["syui"]
|
||||||
description = "A static blog generator with AI features"
|
description = "A static blog generator with AI features"
|
||||||
@@ -49,7 +49,6 @@ regex = "1.0"
|
|||||||
tokio-tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots", "connect"], default-features = false }
|
tokio-tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots", "connect"], default-features = false }
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots"], default-features = false }
|
tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots"], default-features = false }
|
||||||
rpassword = "7.3"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.14"
|
tempfile = "3.14"
|
||||||
|
32
Dockerfile
Normal file
32
Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Multi-stage build for ailog
|
||||||
|
FROM rust:1.75 as builder
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
# Install runtime dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the binary
|
||||||
|
COPY --from=builder /usr/src/app/target/release/ailog /usr/local/bin/ailog
|
||||||
|
|
||||||
|
# Copy blog content
|
||||||
|
COPY my-blog ./blog
|
||||||
|
|
||||||
|
# Build static site
|
||||||
|
RUN ailog build blog
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Run server
|
||||||
|
CMD ["ailog", "serve", "blog"]
|
128
action.yml
Normal file
128
action.yml
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
name: 'ailog Static Site Generator'
|
||||||
|
description: 'AI-powered static blog generator with atproto integration'
|
||||||
|
author: 'syui'
|
||||||
|
|
||||||
|
branding:
|
||||||
|
icon: 'book-open'
|
||||||
|
color: 'orange'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
content-dir:
|
||||||
|
description: 'Content directory containing markdown files'
|
||||||
|
required: false
|
||||||
|
default: 'content'
|
||||||
|
output-dir:
|
||||||
|
description: 'Output directory for generated site'
|
||||||
|
required: false
|
||||||
|
default: 'public'
|
||||||
|
template-dir:
|
||||||
|
description: 'Template directory'
|
||||||
|
required: false
|
||||||
|
default: 'templates'
|
||||||
|
static-dir:
|
||||||
|
description: 'Static assets directory'
|
||||||
|
required: false
|
||||||
|
default: 'static'
|
||||||
|
config-file:
|
||||||
|
description: 'Configuration file path'
|
||||||
|
required: false
|
||||||
|
default: 'ailog.toml'
|
||||||
|
ai-integration:
|
||||||
|
description: 'Enable AI features'
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
|
atproto-integration:
|
||||||
|
description: 'Enable atproto/OAuth features'
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
site-url:
|
||||||
|
description: 'Generated site URL'
|
||||||
|
value: ${{ steps.generate.outputs.site-url }}
|
||||||
|
build-time:
|
||||||
|
description: 'Build time in seconds'
|
||||||
|
value: ${{ steps.generate.outputs.build-time }}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- 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
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# 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
|
||||||
|
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 "Error: No binary found and cargo not available"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Setup Node.js for OAuth app
|
||||||
|
if: ${{ inputs.atproto-integration == 'true' }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Build OAuth app
|
||||||
|
if: ${{ inputs.atproto-integration == 'true' }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ -d "oauth" ]; then
|
||||||
|
cd oauth
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
cp -r dist/* ../${{ inputs.static-dir }}/
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Generate site
|
||||||
|
id: generate
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
start_time=$(date +%s)
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
echo "build-time=${build_time}" >> $GITHUB_OUTPUT
|
||||||
|
echo "site-url=file://$(pwd)/${{ inputs.output-dir }}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Display build summary
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "✅ ailog build completed successfully"
|
||||||
|
echo "📁 Output directory: ${{ inputs.output-dir }}"
|
||||||
|
echo "⏱️ Build time: ${{ steps.generate.outputs.build-time }}s"
|
||||||
|
if [ -d "${{ inputs.output-dir }}" ]; then
|
||||||
|
echo "📄 Generated files:"
|
||||||
|
find ${{ inputs.output-dir }} -type f | head -10
|
||||||
|
fi
|
1
ai_prompt.txt
Normal file
1
ai_prompt.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。
|
Binary file not shown.
@@ -1,24 +1,24 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cb=ai.syui.log
|
cb=ai.syui.log
|
||||||
cl=( $cb.user )
|
cl=( $cb.chat $cb.chat.comment $cb.chat.lang )
|
||||||
f=~/.config/syui/ai/log/config.json
|
|
||||||
|
|
||||||
|
f=~/.config/syui/ai/bot/token.json
|
||||||
default_collection="ai.syui.log.chat.comment"
|
default_collection="ai.syui.log.chat.comment"
|
||||||
default_pds="syu.is"
|
default_pds="bsky.social"
|
||||||
default_did=`cat $f|jq -r .admin.did`
|
default_did=`cat $f|jq -r .did`
|
||||||
default_token=`cat $f|jq -r .admin.access_jwt`
|
default_token=`cat $f|jq -r .accessJwt`
|
||||||
default_refresh=`cat $f|jq -r .admin.refresh_jwt`
|
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
|
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 .admin.access_jwt`
|
default_token=`cat $f|jq -r .accessJwt`
|
||||||
collection=${1:-$default_collection}
|
collection=${1:-$default_collection}
|
||||||
pds=${2:-$default_pds}
|
pds=${2:-$default_pds}
|
||||||
did=${3:-$default_did}
|
did=${3:-$default_did}
|
||||||
token=${4:-$default_token}
|
token=${4:-$default_token}
|
||||||
req=com.atproto.repo.deleteRecord
|
req=com.atproto.repo.deleteRecord
|
||||||
url=https://$pds/xrpc/$req
|
url=https://$pds/xrpc/$req
|
||||||
|
|
||||||
for i in $cl; do
|
for i in $cl; do
|
||||||
echo $i
|
echo $i
|
||||||
rkeys=($(curl -sL "https://$default_pds/xrpc/com.atproto.repo.listRecords?repo=$did&collection=$i&limit=100"|jq -r ".records[]?.uri"|cut -d '/' -f 5))
|
rkeys=($(curl -sL "https://$default_pds/xrpc/com.atproto.repo.listRecords?repo=$did&collection=$i&limit=100"|jq -r ".records[]?.uri"|cut -d '/' -f 5))
|
208
claude.md
208
claude.md
@@ -14,214 +14,6 @@ VITE_OAUTH_COLLECTION_USER=ai.syui.log.user
|
|||||||
VITE_OAUTH_COLLECTION_CHAT=ai.syui.log.chat
|
VITE_OAUTH_COLLECTION_CHAT=ai.syui.log.chat
|
||||||
```
|
```
|
||||||
|
|
||||||
## oauth appの設計
|
|
||||||
|
|
||||||
> ./oauth/.env.production
|
|
||||||
|
|
||||||
```sh
|
|
||||||
VITE_ATPROTO_PDS=syu.is
|
|
||||||
VITE_ADMIN_HANDLE=ai.syui.ai
|
|
||||||
VITE_AI_HANDLE=ai.syui.ai
|
|
||||||
VITE_OAUTH_COLLECTION=ai.syui.log
|
|
||||||
```
|
|
||||||
|
|
||||||
これらは非常にシンプルな流れになっており、すべての項目は、共通します。短縮できる場合があります。handleは変わる可能性があるので、できる限りdidを使いましょう。
|
|
||||||
|
|
||||||
1. handleからpds, didを取得できる ... com.atproto.repo.describeRepo
|
|
||||||
2. pdsが分かれば、pdsApi, bskyApi, plcApiを割り当てられる
|
|
||||||
3. bskyApiが分かれば、getProfileでavatar-uriを取得できる ... app.bsky.actor.getProfile
|
|
||||||
4. pdsAPiからアカウントにあるcollectionのrecordの情報を取得できる ... com.atproto.repo.listRecords
|
|
||||||
|
|
||||||
### コメントを表示する
|
|
||||||
|
|
||||||
1. VITE_ADMIN_HANDLEから管理者のhandleを取得する。
|
|
||||||
2. VITE_ATPROTO_PDSから管理者のアカウントのpdsを取得する。
|
|
||||||
3. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
|
||||||
|
|
||||||
```rust
|
|
||||||
match pds {
|
|
||||||
"bsky.social" | "bsky.app" => NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
},
|
|
||||||
"syu.is" => NetworkConfig {
|
|
||||||
pds_api: "https://syu.is".to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// Default to Bluesky network for unknown PDS
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
4. 管理者アカウントであるVITE_ADMIN_HANDLEとVITE_ATPROTO_PDSから`ai.syui.log.user`というuserlistを取得する。
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${VITE_ADMIN_HANDLE}&collection=ai.syui.log.user"
|
|
||||||
---
|
|
||||||
syui.ai
|
|
||||||
```
|
|
||||||
|
|
||||||
5. ユーザーがわかったら、そのユーザーのpdsを判定する。
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -sL "https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo=syui.ai" |jq -r ".didDoc.service.[].serviceEndpoint"
|
|
||||||
---
|
|
||||||
https://shiitake.us-east.host.bsky.network
|
|
||||||
|
|
||||||
curl -sL "https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo=syui.ai" |jq -r ".did"
|
|
||||||
---
|
|
||||||
did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
|
||||||
```
|
|
||||||
|
|
||||||
6. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
|
||||||
|
|
||||||
```rust
|
|
||||||
match pds {
|
|
||||||
"bsky.social" | "bsky.app" => NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
},
|
|
||||||
"syu.is" => NetworkConfig {
|
|
||||||
pds_api: "https://syu.is".to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// Default to Bluesky network for unknown PDS
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
7. ユーザーの情報を取得、表示する
|
|
||||||
|
|
||||||
```sh
|
|
||||||
bsky_api=https://public.api.bsky.app
|
|
||||||
user_did=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
|
||||||
curl -sL "$bsky_api/xrpc/app.bsky.actor.getProfile?actor=$user_did"|jq -r .avatar
|
|
||||||
---
|
|
||||||
https://cdn.bsky.app/img/avatar/plain/did:plc:uqzpqmrjnptsxezjx4xuh2mn/bafkreid6kcc5pnn4b3ar7mj6vi3eiawhxgkcrw3edgbqeacyrlnlcoetea@jpeg
|
|
||||||
```
|
|
||||||
|
|
||||||
### AIの情報を表示する
|
|
||||||
|
|
||||||
AIが持つ`ai.syui.log.chat.lang`, `ai.syui.log.chat.comment`を表示します。
|
|
||||||
|
|
||||||
なお、これは通常、`VITE_ADMIN_HANDLE`にputRecordされます。そこから情報を読み込みます。`VITE_AI_HANDLE`はそのrecordの`author`のところに入ります。
|
|
||||||
|
|
||||||
```json
|
|
||||||
"author": {
|
|
||||||
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
|
|
||||||
"avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:4hqjfn7m6n5hno3doamuhgef/bafkreiaxkv624mffw3cfyi67ufxtwuwsy2mjw2ygezsvtd44ycbgkfdo2a@jpeg",
|
|
||||||
"handle": "yui.syui.ai",
|
|
||||||
"displayName": "ai"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
1. VITE_ADMIN_HANDLEから管理者のhandleを取得する。
|
|
||||||
2. VITE_ATPROTO_PDSから管理者のアカウントのpdsを取得する。
|
|
||||||
3. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
|
||||||
|
|
||||||
```rust
|
|
||||||
match pds {
|
|
||||||
"bsky.social" | "bsky.app" => NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
},
|
|
||||||
"syu.is" => NetworkConfig {
|
|
||||||
pds_api: "https://syu.is".to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// Default to Bluesky network for unknown PDS
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
4. 管理者アカウントであるVITE_ADMIN_HANDLEとVITE_ATPROTO_PDSから`ai.syui.log.chat.lang`, `ai.syui.log.chat.comment`を取得する。
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${VITE_ADMIN_HANDLE}&collection=ai.syui.log.chat.comment"
|
|
||||||
```
|
|
||||||
|
|
||||||
5. AIのprofileを取得する。
|
|
||||||
|
|
||||||
```sh
|
|
||||||
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.describeRepo?repo=$VITE_AI_HANDLE" |jq -r ".didDoc.service.[].serviceEndpoint"
|
|
||||||
---
|
|
||||||
https://syu.is
|
|
||||||
|
|
||||||
curl -sL "https://${VITE_ATPROTO_PDS}/xrpc/com.atproto.repo.describeRepo?repo=$VITE_AI_HANDLE" |jq -r ".did"
|
|
||||||
did:plc:6qyecktefllvenje24fcxnie
|
|
||||||
```
|
|
||||||
|
|
||||||
6. pdsからpdsApi, bskApi, plcApiを割り当てる。
|
|
||||||
|
|
||||||
```rust
|
|
||||||
match pds {
|
|
||||||
"bsky.social" | "bsky.app" => NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
},
|
|
||||||
"syu.is" => NetworkConfig {
|
|
||||||
pds_api: "https://syu.is".to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// Default to Bluesky network for unknown PDS
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
7. AIの情報を取得、表示する
|
|
||||||
|
|
||||||
```sh
|
|
||||||
bsky_api=https://bsky.syu.is
|
|
||||||
user_did=did:plc:6qyecktefllvenje24fcxnie
|
|
||||||
curl -sL "$bsky_api/xrpc/app.bsky.actor.getProfile?actor=$user_did"|jq -r .avatar
|
|
||||||
---
|
|
||||||
https://bsky.syu.is/img/avatar/plain/did:plc:6qyecktefllvenje24fcxnie/bafkreiet4pwlnshk7igra5flf2fuxpg2bhvf2apts4rqwcr56hzhgycii4@jpeg
|
|
||||||
```
|
|
||||||
|
|
||||||
## 中核思想
|
## 中核思想
|
||||||
- **存在子理論**: この世界で最も小さいもの(存在子/ai)の探求
|
- **存在子理論**: この世界で最も小さいもの(存在子/ai)の探求
|
||||||
- **唯一性原則**: 現実の個人の唯一性をすべてのシステムで担保
|
- **唯一性原則**: 現実の個人の唯一性をすべてのシステムで担保
|
||||||
|
18
cloudflared-config.yml
Normal file
18
cloudflared-config.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
tunnel: ec5a422d-7678-4e73-bf38-6105ffd4766a
|
||||||
|
credentials-file: /Users/syui/.cloudflared/ec5a422d-7678-4e73-bf38-6105ffd4766a.json
|
||||||
|
|
||||||
|
ingress:
|
||||||
|
- hostname: log.syui.ai
|
||||||
|
service: http://localhost:4173
|
||||||
|
originRequest:
|
||||||
|
noHappyEyeballs: true
|
||||||
|
|
||||||
|
- hostname: ollama.syui.ai
|
||||||
|
service: http://localhost:11434
|
||||||
|
originRequest:
|
||||||
|
noHappyEyeballs: true
|
||||||
|
httpHostHeader: "localhost:11434"
|
||||||
|
# Cloudflare Accessを無効化する場合は以下をコメントアウト
|
||||||
|
# accessPolicy: bypass
|
||||||
|
|
||||||
|
- service: http_status:404
|
@@ -17,15 +17,13 @@ comment_moderation = false
|
|||||||
ask_ai = true
|
ask_ai = true
|
||||||
provider = "ollama"
|
provider = "ollama"
|
||||||
model = "gemma3:4b"
|
model = "gemma3:4b"
|
||||||
host = "https://localhost:11434"
|
host = "https://ollama.syui.ai"
|
||||||
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
handle = "ai.syui.ai"
|
ai_did = "did:plc:4hqjfn7m6n5hno3doamuhgef"
|
||||||
#num_predict = 200
|
|
||||||
|
|
||||||
[oauth]
|
[oauth]
|
||||||
json = "client-metadata.json"
|
json = "client-metadata.json"
|
||||||
redirect = "oauth/callback"
|
redirect = "oauth/callback"
|
||||||
admin = "ai.syui.ai"
|
admin = "did:plc:uqzpqmrjnptsxezjx4xuh2mn"
|
||||||
collection = "ai.syui.log"
|
collection = "ai.syui.log"
|
||||||
pds = "syu.is"
|
bsky_api = "https://public.api.bsky.app"
|
||||||
handle_list = ["syui.syui.ai", "yui.syui.ai", "ai.syui.ai", "syui.syu.is", "ai.syu.is", "ai.ai"]
|
|
||||||
|
@@ -57,28 +57,24 @@ $ npm run build
|
|||||||
$ npm run preview
|
$ npm run preview
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh:ouath/.env.production
|
```sh
|
||||||
# Production environment variables
|
# Production environment variables
|
||||||
VITE_APP_HOST=https://syui.ai
|
VITE_APP_HOST=https://example.com
|
||||||
VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
VITE_OAUTH_CLIENT_ID=https://example.com/client-metadata.json
|
||||||
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
VITE_OAUTH_REDIRECT_URI=https://example.com/oauth/callback
|
||||||
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
||||||
|
|
||||||
# Base collection (all others are derived via getCollectionNames)
|
# Collection names for OAuth app
|
||||||
VITE_OAUTH_COLLECTION=ai.syui.log
|
VITE_COLLECTION_COMMENT=ai.syui.log
|
||||||
|
VITE_COLLECTION_USER=ai.syui.log.user
|
||||||
|
VITE_COLLECTION_CHAT=ai.syui.log.chat
|
||||||
|
|
||||||
# AI Configuration
|
# Collection names for ailog (backward compatibility)
|
||||||
VITE_AI_ENABLED=true
|
AILOG_COLLECTION_COMMENT=ai.syui.log
|
||||||
VITE_AI_ASK_AI=true
|
AILOG_COLLECTION_USER=ai.syui.log.user
|
||||||
VITE_AI_PROVIDER=ollama
|
|
||||||
VITE_AI_MODEL=gemma3:4b
|
|
||||||
VITE_AI_HOST=https://ollama.syui.ai
|
|
||||||
VITE_AI_SYSTEM_PROMPT="ai"
|
|
||||||
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
|
||||||
|
|
||||||
# API Configuration
|
# API Configuration
|
||||||
VITE_BSKY_PUBLIC_API=https://public.api.bsky.app
|
VITE_BSKY_PUBLIC_API=https://public.api.bsky.app
|
||||||
VITE_ATPROTO_API=https://bsky.social
|
|
||||||
```
|
```
|
||||||
|
|
||||||
これは`ailog oauth build my-blog`で`./my-blog/config.toml`から`./oauth/.env.production`が生成されます。
|
これは`ailog oauth build my-blog`で`./my-blog/config.toml`から`./oauth/.env.production`が生成されます。
|
||||||
@@ -119,8 +115,15 @@ $ cloudflared tunnel --config cloudflared-config.yml run
|
|||||||
$ cloudflared tunnel route dns ${uuid} example.com
|
$ cloudflared tunnel route dns ${uuid} example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
|
以下の2つのcollection recordを生成します。ユーザーには`ai.syui.log`が生成され、ここにコメントが記録されます。それを取得して表示しています。`ai.syui.log.user`は管理者である`VITE_ADMIN_DID`用です。
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ailog auth init
|
VITE_COLLECTION_COMMENT=ai.syui.log
|
||||||
|
VITE_COLLECTION_USER=ai.syui.log.user
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ ailog auth login
|
||||||
$ ailog stream server
|
$ ailog stream server
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -132,9 +135,8 @@ $ ailog stream server
|
|||||||
|
|
||||||
`ask-AI`の仕組みは割愛します。後に変更される可能性が高いと思います。
|
`ask-AI`の仕組みは割愛します。後に変更される可能性が高いと思います。
|
||||||
|
|
||||||
`llm`, `mcp`, `atproto`などの組み合わせです。
|
local llm, mcp, atprotoと組み合わせです。
|
||||||
|
|
||||||
現在、`/index.json`を監視して、更新があれば、翻訳などを行い自動ポストする機能があります。
|
|
||||||
|
|
||||||
## code syntax
|
## code syntax
|
||||||
|
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
# Production environment variables
|
|
||||||
VITE_APP_HOST=https://syui.ai
|
|
||||||
VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
|
||||||
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
|
||||||
|
|
||||||
# Handle-based Configuration (DIDs resolved at runtime)
|
|
||||||
VITE_ATPROTO_PDS=syu.is
|
|
||||||
VITE_ADMIN_HANDLE=ai.syui.ai
|
|
||||||
VITE_AI_HANDLE=ai.syui.ai
|
|
||||||
VITE_OAUTH_COLLECTION=ai.syui.log
|
|
||||||
VITE_ATPROTO_WEB_URL=https://bsky.app
|
|
||||||
VITE_ATPROTO_HANDLE_LIST=["syui.syui.ai", "yui.syui.ai", "ai.syui.ai", "syui.syu.is", "ai.syu.is", "ai.ai"]
|
|
||||||
|
|
||||||
# AI Configuration
|
|
||||||
VITE_AI_ENABLED=true
|
|
||||||
VITE_AI_ASK_AI=true
|
|
||||||
VITE_AI_PROVIDER=ollama
|
|
||||||
VITE_AI_MODEL=gemma3:4b
|
|
||||||
VITE_AI_HOST=https://localhost:11434
|
|
||||||
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
|
@@ -248,7 +248,7 @@ a.view-markdown:any-link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.post-title a {
|
.post-title a {
|
||||||
color: var(--theme-color);
|
color: #1f2328;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -822,13 +822,6 @@ article.article-content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comment-section {
|
.comment-section {
|
||||||
max-width: 100% !important;
|
|
||||||
padding: 0px !important;
|
|
||||||
margin: 0px !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-container {
|
|
||||||
max-width: 100% !important;
|
|
||||||
padding: 0px !important;
|
padding: 0px !important;
|
||||||
margin: 0px !important;
|
margin: 0px !important;
|
||||||
}
|
}
|
||||||
|
3
my-blog/static/index.html
Normal file
3
my-blog/static/index.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<!-- OAuth Comment System - Load globally for session management -->
|
||||||
|
<script type="module" crossorigin src="/assets/comment-atproto-C3utAhPv.js"></script>
|
||||||
|
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-BH-72ESb.css">
|
@@ -253,20 +253,6 @@ function setupAskAIEventListeners() {
|
|||||||
handleAIResponse(event.detail);
|
handleAIResponse(event.detail);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Track IME composition state
|
|
||||||
let isComposing = false;
|
|
||||||
const aiQuestionInput = document.getElementById('aiQuestion');
|
|
||||||
|
|
||||||
if (aiQuestionInput) {
|
|
||||||
aiQuestionInput.addEventListener('compositionstart', function() {
|
|
||||||
isComposing = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
aiQuestionInput.addEventListener('compositionend', function() {
|
|
||||||
isComposing = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
@@ -276,8 +262,8 @@ function setupAskAIEventListeners() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter key to send message (only when not composing Japanese input)
|
// Enter key to send message
|
||||||
if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey && !isComposing) {
|
if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
askQuestion();
|
askQuestion();
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
<footer class="main-footer">
|
<footer class="main-footer">
|
||||||
<div class="footer-social">
|
<div class="footer-social">
|
||||||
<a href="https://syu.is/syui" target="_blank"><i class="fab fa-bluesky"></i></a>
|
<a href="https://web.syu.is/@syui" target="_blank"><i class="fab fa-bluesky"></i></a>
|
||||||
<a href="https://git.syui.ai/ai" target="_blank"><span class="icon-ai"></span></a>
|
<a href="https://git.syui.ai/ai" target="_blank"><span class="icon-ai"></span></a>
|
||||||
<a href="https://git.syui.ai/syui" target="_blank"><span class="icon-git"></span></a>
|
<a href="https://git.syui.ai/syui" target="_blank"><span class="icon-git"></span></a>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -20,6 +20,19 @@
|
|||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
|
{% if post.excerpt %}
|
||||||
|
<p class="post-excerpt">{{ post.excerpt }}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="post-actions">
|
||||||
|
<a href="{{ post.url }}" class="read-more">Read more</a>
|
||||||
|
{% if post.markdown_url %}
|
||||||
|
<a href="{{ post.markdown_url }}" class="view-markdown" title="View Markdown">.md</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if post.translation_url %}
|
||||||
|
<a href="{{ post.translation_url }}" class="view-translation" title="View Translation">🌐</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
3
my-blog/templates/oauth-assets.html
Normal file
3
my-blog/templates/oauth-assets.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<!-- OAuth Comment System - Load globally for session management -->
|
||||||
|
<script type="module" crossorigin src="/assets/comment-atproto-C3utAhPv.js"></script>
|
||||||
|
<link rel="stylesheet" crossorigin href="/assets/comment-atproto-BH-72ESb.css">
|
@@ -2,14 +2,10 @@
|
|||||||
VITE_APP_HOST=https://syui.ai
|
VITE_APP_HOST=https://syui.ai
|
||||||
VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
VITE_OAUTH_CLIENT_ID=https://syui.ai/client-metadata.json
|
||||||
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
VITE_OAUTH_REDIRECT_URI=https://syui.ai/oauth/callback
|
||||||
|
VITE_ADMIN_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
||||||
|
|
||||||
# Handle-based Configuration (DIDs resolved at runtime)
|
# Base collection (all others are derived via getCollectionNames)
|
||||||
VITE_ATPROTO_PDS=syu.is
|
|
||||||
VITE_ADMIN_HANDLE=ai.syui.ai
|
|
||||||
VITE_AI_HANDLE=ai.syui.ai
|
|
||||||
VITE_OAUTH_COLLECTION=ai.syui.log
|
VITE_OAUTH_COLLECTION=ai.syui.log
|
||||||
VITE_ATPROTO_WEB_URL=https://bsky.app
|
|
||||||
VITE_ATPROTO_HANDLE_LIST=["syui.syui.ai","yui.syui.ai","syui.syu.is","ai.syu.is"]
|
|
||||||
|
|
||||||
# AI Configuration
|
# AI Configuration
|
||||||
VITE_AI_ENABLED=true
|
VITE_AI_ENABLED=true
|
||||||
@@ -18,4 +14,8 @@ VITE_AI_PROVIDER=ollama
|
|||||||
VITE_AI_MODEL=gemma3:4b
|
VITE_AI_MODEL=gemma3:4b
|
||||||
VITE_AI_HOST=https://ollama.syui.ai
|
VITE_AI_HOST=https://ollama.syui.ai
|
||||||
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
|
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
||||||
|
|
||||||
|
# API Configuration
|
||||||
|
VITE_BSKY_PUBLIC_API=https://public.api.bsky.app
|
||||||
|
VITE_ATPROTO_API=https://bsky.social
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aicard",
|
"name": "aicard",
|
||||||
"version": "0.1.1",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --mode development",
|
"dev": "vite --mode development",
|
||||||
|
@@ -168,14 +168,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1000px) {
|
@media (max-width: 1000px) {
|
||||||
* {
|
|
||||||
max-width: 100% !important;
|
|
||||||
box-sizing: border-box !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app .app-main {
|
.app .app-main {
|
||||||
max-width: 100% !important;
|
|
||||||
margin: 0 !important;
|
|
||||||
padding: 0px !important;
|
padding: 0px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +186,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comment-section {
|
.comment-section {
|
||||||
padding: 30px 0 !important;
|
padding: 0px !important;
|
||||||
margin: 0px !important;
|
margin: 0px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +209,6 @@
|
|||||||
/* Ensure full width on mobile */
|
/* Ensure full width on mobile */
|
||||||
.app {
|
.app {
|
||||||
max-width: 100vw !important;
|
max-width: 100vw !important;
|
||||||
overflow-x: hidden !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix button overflow */
|
/* Fix button overflow */
|
||||||
@@ -332,14 +324,6 @@
|
|||||||
/* padding: 20px; - removed to avoid double padding */
|
/* padding: 20px; - removed to avoid double padding */
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.comment-section {
|
|
||||||
max-width: 100%;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.auth-section {
|
.auth-section {
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
@@ -350,38 +334,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-section.search-bar-layout {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 10px;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-section.search-bar-layout .handle-input {
|
|
||||||
flex: 1;
|
|
||||||
margin: 0;
|
|
||||||
padding: 10px 15px;
|
|
||||||
font-size: 16px;
|
|
||||||
border: 1px solid #dee2e6;
|
|
||||||
border-radius: 6px 0 0 6px;
|
|
||||||
background: white;
|
|
||||||
outline: none;
|
|
||||||
transition: border-color 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-section.search-bar-layout .handle-input:focus {
|
|
||||||
border-color: var(--theme-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-section.search-bar-layout .atproto-button {
|
|
||||||
margin: 0;
|
|
||||||
padding: 10px 20px;
|
|
||||||
border-radius: 0 6px 6px 0;
|
|
||||||
min-width: 50px;
|
|
||||||
font-weight: bold;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.atproto-button {
|
.atproto-button {
|
||||||
background: var(--theme-color);
|
background: var(--theme-color);
|
||||||
color: var(--white);
|
color: var(--white);
|
||||||
@@ -415,30 +367,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override for search bar layout */
|
|
||||||
.search-bar-layout .handle-input {
|
|
||||||
width: auto;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mobile responsive for search bar */
|
|
||||||
@media (max-width: 480px) {
|
|
||||||
.auth-section.search-bar-layout {
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-section.search-bar-layout .handle-input {
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-section.search-bar-layout .atproto-button {
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-hint {
|
.auth-hint {
|
||||||
color: #6c757d;
|
color: #6c757d;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
@@ -571,8 +499,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comments-list {
|
.comments-list {
|
||||||
|
border: 1px solid #ddd;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 0px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comments-header {
|
.comments-header {
|
||||||
@@ -931,6 +860,28 @@
|
|||||||
background: #f6f8fa;
|
background: #f6f8fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* AI Chat History */
|
||||||
|
.ai-chat-list {
|
||||||
|
max-width: 100%;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-item {
|
||||||
|
border: 1px solid #d1d9e0;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 16px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.chat-actions {
|
.chat-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -982,7 +933,3 @@
|
|||||||
color: #656d76;
|
color: #656d76;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-message.comment-style {
|
|
||||||
border-left: 4px solid var(--theme-color);
|
|
||||||
}
|
|
||||||
|
@@ -4,7 +4,6 @@ import { AIChat } from './components/AIChat';
|
|||||||
import { authService, User } from './services/auth';
|
import { authService, User } from './services/auth';
|
||||||
import { atprotoOAuthService } from './services/atproto-oauth';
|
import { atprotoOAuthService } from './services/atproto-oauth';
|
||||||
import { appConfig, getCollectionNames } from './config/app';
|
import { appConfig, getCollectionNames } from './config/app';
|
||||||
import { getProfileForUser, detectPdsFromHandle, getApiUrlForUser, verifyPdsDetection, getNetworkConfigFromPdsEndpoint, getNetworkConfig } from './utils/pds-detection';
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@@ -29,35 +28,8 @@ function App() {
|
|||||||
const [aiChatHistory, setAiChatHistory] = useState<any[]>([]);
|
const [aiChatHistory, setAiChatHistory] = useState<any[]>([]);
|
||||||
const [langEnRecords, setLangEnRecords] = useState<any[]>([]);
|
const [langEnRecords, setLangEnRecords] = useState<any[]>([]);
|
||||||
const [aiCommentRecords, setAiCommentRecords] = useState<any[]>([]);
|
const [aiCommentRecords, setAiCommentRecords] = useState<any[]>([]);
|
||||||
const [aiProfile, setAiProfile] = useState<any>(null);
|
|
||||||
|
|
||||||
const [adminDid, setAdminDid] = useState<string | null>(null);
|
|
||||||
const [aiDid, setAiDid] = useState<string | null>(null);
|
|
||||||
|
|
||||||
// ハンドルからDIDを解決する関数
|
|
||||||
const resolveHandleToDid = async (handle: string): Promise<string | null> => {
|
|
||||||
try {
|
|
||||||
const profile = await import('./utils/pds-detection').then(m => m.getProfileForUser(handle));
|
|
||||||
return profile?.did || null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 管理者とAIのDIDを解決
|
|
||||||
const resolveAdminAndAiDids = async () => {
|
|
||||||
const [resolvedAdminDid, resolvedAiDid] = await Promise.all([
|
|
||||||
resolveHandleToDid(appConfig.adminHandle),
|
|
||||||
resolveHandleToDid(appConfig.aiHandle)
|
|
||||||
]);
|
|
||||||
|
|
||||||
setAdminDid(resolvedAdminDid || appConfig.adminDid);
|
|
||||||
setAiDid(resolvedAiDid || appConfig.aiDid);
|
|
||||||
};
|
|
||||||
|
|
||||||
resolveAdminAndAiDids();
|
|
||||||
|
|
||||||
// Setup Jetstream WebSocket for real-time comments (optional)
|
// Setup Jetstream WebSocket for real-time comments (optional)
|
||||||
const setupJetstream = () => {
|
const setupJetstream = () => {
|
||||||
try {
|
try {
|
||||||
@@ -109,8 +81,6 @@ function App() {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// DID解決が完了してからコメントとチャット履歴を読み込む
|
|
||||||
const loadDataAfterDidResolution = () => {
|
|
||||||
// キャッシュがなければ、ATProtoから取得(認証状態に関係なく)
|
// キャッシュがなければ、ATProtoから取得(認証状態に関係なく)
|
||||||
if (!loadCachedComments()) {
|
if (!loadCachedComments()) {
|
||||||
loadAllComments(); // URLフィルタリングを無効にして全コメント表示
|
loadAllComments(); // URLフィルタリングを無効にして全コメント表示
|
||||||
@@ -119,80 +89,6 @@ function App() {
|
|||||||
// Load AI chat history (認証状態に関係なく、全ユーザーのチャット履歴を表示)
|
// Load AI chat history (認証状態に関係なく、全ユーザーのチャット履歴を表示)
|
||||||
loadAiChatHistory();
|
loadAiChatHistory();
|
||||||
|
|
||||||
// Load AI generated content (lang:en and AI comments)
|
|
||||||
loadAIGeneratedContent();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Wait for DID resolution before loading data
|
|
||||||
if (adminDid && aiDid) {
|
|
||||||
loadDataAfterDidResolution();
|
|
||||||
} else {
|
|
||||||
// Wait a bit and try again
|
|
||||||
setTimeout(() => {
|
|
||||||
if (adminDid && aiDid) {
|
|
||||||
loadDataAfterDidResolution();
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load AI profile from handle
|
|
||||||
const loadAiProfile = async () => {
|
|
||||||
try {
|
|
||||||
// Use VITE_AI_HANDLE to detect PDS and get profile
|
|
||||||
const handle = appConfig.aiHandle;
|
|
||||||
if (!handle) {
|
|
||||||
throw new Error('No AI handle configured');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect PDS: Use VITE_ATPROTO_PDS if handle matches admin/ai handles
|
|
||||||
let pds;
|
|
||||||
if (handle === appConfig.adminHandle || handle === appConfig.aiHandle) {
|
|
||||||
// Use configured PDS for admin/ai handles
|
|
||||||
pds = appConfig.atprotoPds || 'syu.is';
|
|
||||||
} else {
|
|
||||||
// Use handle-based detection for other handles
|
|
||||||
pds = detectPdsFromHandle(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = getNetworkConfigFromPdsEndpoint(`https://${pds}`);
|
|
||||||
const apiEndpoint = config.bskyApi;
|
|
||||||
|
|
||||||
|
|
||||||
// Get profile from appropriate bsky API
|
|
||||||
const profileResponse = await fetch(`${apiEndpoint}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`);
|
|
||||||
if (profileResponse.ok) {
|
|
||||||
const profileData = await profileResponse.json();
|
|
||||||
setAiProfile({
|
|
||||||
did: profileData.did || appConfig.aiDid,
|
|
||||||
handle: profileData.handle || handle,
|
|
||||||
displayName: profileData.displayName || appConfig.aiDisplayName || 'ai',
|
|
||||||
avatar: profileData.avatar || generatePlaceholderAvatar(handle),
|
|
||||||
description: profileData.description || appConfig.aiDescription || ''
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Fallback to config values
|
|
||||||
setAiProfile({
|
|
||||||
did: appConfig.aiDid,
|
|
||||||
handle: handle,
|
|
||||||
displayName: appConfig.aiDisplayName || 'ai',
|
|
||||||
avatar: generatePlaceholderAvatar(handle),
|
|
||||||
description: appConfig.aiDescription || ''
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// Failed to load AI profile
|
|
||||||
// Fallback to config values
|
|
||||||
setAiProfile({
|
|
||||||
did: appConfig.aiDid,
|
|
||||||
handle: appConfig.aiHandle,
|
|
||||||
displayName: appConfig.aiDisplayName || 'ai',
|
|
||||||
avatar: generatePlaceholderAvatar(appConfig.aiHandle || 'ai'),
|
|
||||||
description: appConfig.aiDescription || ''
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
loadAiProfile();
|
|
||||||
|
|
||||||
// Handle popstate events for mock OAuth flow
|
// Handle popstate events for mock OAuth flow
|
||||||
const handlePopState = () => {
|
const handlePopState = () => {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
@@ -223,14 +119,6 @@ function App() {
|
|||||||
// Ensure handle is not DID
|
// Ensure handle is not DID
|
||||||
const handle = oauthResult.handle !== oauthResult.did ? oauthResult.handle : oauthResult.handle;
|
const handle = oauthResult.handle !== oauthResult.did ? oauthResult.handle : oauthResult.handle;
|
||||||
|
|
||||||
// Check if handle is allowed
|
|
||||||
if (appConfig.allowedHandles.length > 0 && !appConfig.allowedHandles.includes(handle)) {
|
|
||||||
// Handle not in allowed list
|
|
||||||
setError(`Access denied: ${handle} is not authorized for this application.`);
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get user profile including avatar
|
// Get user profile including avatar
|
||||||
const userProfile = await getUserProfile(oauthResult.did, handle);
|
const userProfile = await getUserProfile(oauthResult.did, handle);
|
||||||
setUser(userProfile);
|
setUser(userProfile);
|
||||||
@@ -243,7 +131,7 @@ function App() {
|
|||||||
loadAiChatHistory();
|
loadAiChatHistory();
|
||||||
|
|
||||||
// Load user list records if admin
|
// Load user list records if admin
|
||||||
if (userProfile.did === adminDid) {
|
if (userProfile.did === appConfig.adminDid) {
|
||||||
loadUserListRecords();
|
loadUserListRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,14 +142,6 @@ function App() {
|
|||||||
// Fallback to legacy auth
|
// Fallback to legacy auth
|
||||||
const verifiedUser = await authService.verify();
|
const verifiedUser = await authService.verify();
|
||||||
if (verifiedUser) {
|
if (verifiedUser) {
|
||||||
// Check if handle is allowed
|
|
||||||
if (appConfig.allowedHandles.length > 0 && !appConfig.allowedHandles.includes(verifiedUser.handle)) {
|
|
||||||
// Handle not in allowed list
|
|
||||||
setError(`Access denied: ${verifiedUser.handle} is not authorized for this application.`);
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setUser(verifiedUser);
|
setUser(verifiedUser);
|
||||||
|
|
||||||
// Load all comments for display (this will be the default view)
|
// Load all comments for display (this will be the default view)
|
||||||
@@ -269,7 +149,7 @@ function App() {
|
|||||||
loadAllComments();
|
loadAllComments();
|
||||||
|
|
||||||
// Load user list records if admin
|
// Load user list records if admin
|
||||||
if (verifiedUser.did === adminDid) {
|
if (verifiedUser.did === appConfig.adminDid) {
|
||||||
loadUserListRecords();
|
loadUserListRecords();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,15 +169,6 @@ function App() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// DID解決完了時にデータを再読み込み
|
|
||||||
useEffect(() => {
|
|
||||||
if (adminDid && aiDid) {
|
|
||||||
loadAllComments();
|
|
||||||
loadAiChatHistory();
|
|
||||||
loadAIGeneratedContent();
|
|
||||||
}
|
|
||||||
}, [adminDid, aiDid]);
|
|
||||||
|
|
||||||
const getUserProfile = async (did: string, handle: string): Promise<User> => {
|
const getUserProfile = async (did: string, handle: string): Promise<User> => {
|
||||||
try {
|
try {
|
||||||
const agent = atprotoOAuthService.getAgent();
|
const agent = atprotoOAuthService.getAgent();
|
||||||
@@ -335,21 +206,12 @@ function App() {
|
|||||||
const loadAiChatHistory = async () => {
|
const loadAiChatHistory = async () => {
|
||||||
try {
|
try {
|
||||||
// Load all chat records from users in admin's user list
|
// Load all chat records from users in admin's user list
|
||||||
const currentAdminDid = adminDid || appConfig.adminDid;
|
const adminDid = appConfig.adminDid;
|
||||||
|
const atprotoApi = appConfig.atprotoApi || 'https://bsky.social';
|
||||||
// Don't proceed if we don't have a valid DID
|
|
||||||
if (!currentAdminDid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use admin's PDS from config
|
|
||||||
const adminConfig = getNetworkConfig(appConfig.atprotoPds);
|
|
||||||
const collections = getCollectionNames(appConfig.collections.base);
|
const collections = getCollectionNames(appConfig.collections.base);
|
||||||
|
|
||||||
// First, get user list from admin using their proper PDS
|
// First, get user list from admin
|
||||||
const adminPdsEndpoint = adminConfig.pdsApi;
|
const userListResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(collections.user)}&limit=100`);
|
||||||
|
|
||||||
const userListResponse = await fetch(`${adminPdsEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(currentAdminDid)}&collection=${encodeURIComponent(collections.user)}&limit=100`);
|
|
||||||
|
|
||||||
if (!userListResponse.ok) {
|
if (!userListResponse.ok) {
|
||||||
setAiChatHistory([]);
|
setAiChatHistory([]);
|
||||||
@@ -372,25 +234,15 @@ function App() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Always include admin DID to check admin's own chats
|
// Always include admin DID to check admin's own chats
|
||||||
allUserDids.push(currentAdminDid);
|
allUserDids.push(adminDid);
|
||||||
|
|
||||||
const userDids = [...new Set(allUserDids)];
|
const userDids = [...new Set(allUserDids)];
|
||||||
|
|
||||||
// Load chat records from all registered users (including admin) using per-user PDS detection
|
// Load chat records from all registered users (including admin)
|
||||||
const allChatRecords = [];
|
const allChatRecords = [];
|
||||||
for (const userDid of userDids) {
|
for (const userDid of userDids) {
|
||||||
try {
|
try {
|
||||||
// Use per-user PDS detection for each user's chat records
|
const chatResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(userDid)}&collection=${encodeURIComponent(collections.chat)}&limit=100`);
|
||||||
let userPdsEndpoint;
|
|
||||||
try {
|
|
||||||
const resolved = await import('./utils/pds-detection').then(m => m.resolvePdsFromRepo(userDid));
|
|
||||||
const config = await import('./utils/pds-detection').then(m => m.getNetworkConfigFromPdsEndpoint(resolved.pds));
|
|
||||||
userPdsEndpoint = config.pdsApi;
|
|
||||||
} catch {
|
|
||||||
userPdsEndpoint = atprotoApi; // Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatResponse = await fetch(`${userPdsEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(userDid)}&collection=${encodeURIComponent(collections.chat)}&limit=100`);
|
|
||||||
|
|
||||||
if (chatResponse.ok) {
|
if (chatResponse.ok) {
|
||||||
const chatData = await chatResponse.json();
|
const chatData = await chatResponse.json();
|
||||||
@@ -407,8 +259,8 @@ function App() {
|
|||||||
if (appConfig.rkey) {
|
if (appConfig.rkey) {
|
||||||
// On post page: show only chats for this specific post
|
// On post page: show only chats for this specific post
|
||||||
filteredRecords = allChatRecords.filter(record => {
|
filteredRecords = allChatRecords.filter(record => {
|
||||||
const recordRkey = record.value.post?.url ? new URL(record.value.post.url).pathname.split('/').pop()?.replace(/\.html$/, '') : '';
|
const recordPath = record.value.post?.url ? new URL(record.value.post.url).pathname : '';
|
||||||
return recordRkey === appConfig.rkey;
|
return recordPath === window.location.pathname;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// On top page: show latest 3 records from all pages
|
// On top page: show latest 3 records from all pages
|
||||||
@@ -440,54 +292,42 @@ function App() {
|
|||||||
// Load AI generated content from admin DID
|
// Load AI generated content from admin DID
|
||||||
const loadAIGeneratedContent = async () => {
|
const loadAIGeneratedContent = async () => {
|
||||||
try {
|
try {
|
||||||
const currentAdminDid = adminDid || appConfig.adminDid;
|
const adminDid = appConfig.adminDid;
|
||||||
|
const atprotoApi = appConfig.atprotoApi || 'https://bsky.social';
|
||||||
// Don't proceed if we don't have a valid DID
|
|
||||||
if (!currentAdminDid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use admin's PDS for collection access (from config)
|
|
||||||
const adminConfig = getNetworkConfig(appConfig.atprotoPds);
|
|
||||||
const atprotoApi = adminConfig.pdsApi;
|
|
||||||
const collections = getCollectionNames(appConfig.collections.base);
|
const collections = getCollectionNames(appConfig.collections.base);
|
||||||
|
|
||||||
// Load lang:en records
|
// Load lang:en records
|
||||||
const langResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(currentAdminDid)}&collection=${encodeURIComponent(collections.chatLang)}&limit=100`);
|
const langResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(collections.chatLang)}&limit=100`);
|
||||||
if (langResponse.ok) {
|
if (langResponse.ok) {
|
||||||
const langData = await langResponse.json();
|
const langData = await langResponse.json();
|
||||||
const langRecords = langData.records || [];
|
const langRecords = langData.records || [];
|
||||||
|
|
||||||
// Filter by current page rkey if on post page
|
// Filter by current page path if on post page
|
||||||
const filteredLangRecords = appConfig.rkey
|
const filteredLangRecords = appConfig.rkey
|
||||||
? langRecords.filter(record => {
|
? langRecords.filter(record => {
|
||||||
// Compare rkey only (last part of path)
|
// Compare path only, not full URL to support localhost vs production
|
||||||
const recordRkey = record.value.post?.url ? new URL(record.value.post.url).pathname.split('/').pop()?.replace(/\.html$/, '') : '';
|
const recordPath = record.value.post?.url ? new URL(record.value.post.url).pathname :
|
||||||
return recordRkey === appConfig.rkey;
|
record.value.url ? new URL(record.value.url).pathname : '';
|
||||||
|
return recordPath === window.location.pathname;
|
||||||
})
|
})
|
||||||
: langRecords.slice(0, 3); // Top page: latest 3
|
: langRecords.slice(0, 3); // Top page: latest 3
|
||||||
|
|
||||||
setLangEnRecords(filteredLangRecords);
|
setLangEnRecords(filteredLangRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load AI comment records from admin account (not AI account)
|
// Load AI comment records
|
||||||
if (!currentAdminDid) {
|
const commentResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(collections.chatComment)}&limit=100`);
|
||||||
console.warn('No Admin DID available, skipping AI comment loading');
|
|
||||||
setAiCommentRecords([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commentResponse = await fetch(`${atprotoApi}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(currentAdminDid)}&collection=${encodeURIComponent(collections.chatComment)}&limit=100`);
|
|
||||||
if (commentResponse.ok) {
|
if (commentResponse.ok) {
|
||||||
const commentData = await commentResponse.json();
|
const commentData = await commentResponse.json();
|
||||||
const commentRecords = commentData.records || [];
|
const commentRecords = commentData.records || [];
|
||||||
|
|
||||||
// Filter by current page rkey if on post page
|
// Filter by current page path if on post page
|
||||||
const filteredCommentRecords = appConfig.rkey
|
const filteredCommentRecords = appConfig.rkey
|
||||||
? commentRecords.filter(record => {
|
? commentRecords.filter(record => {
|
||||||
// Compare rkey only (last part of path)
|
// Compare path only, not full URL to support localhost vs production
|
||||||
const recordRkey = record.value.post?.url ? new URL(record.value.post.url).pathname.split('/').pop()?.replace(/\.html$/, '') : '';
|
const recordPath = record.value.post?.url ? new URL(record.value.post.url).pathname :
|
||||||
return recordRkey === appConfig.rkey;
|
record.value.url ? new URL(record.value.url).pathname : '';
|
||||||
|
return recordPath === window.location.pathname;
|
||||||
})
|
})
|
||||||
: commentRecords.slice(0, 3); // Top page: latest 3
|
: commentRecords.slice(0, 3); // Top page: latest 3
|
||||||
|
|
||||||
@@ -513,49 +353,26 @@ function App() {
|
|||||||
});
|
});
|
||||||
const userComments = response.data.records || [];
|
const userComments = response.data.records || [];
|
||||||
|
|
||||||
// Enhance comments with fresh profile information
|
// Enhance comments with profile information if missing
|
||||||
const enhancedComments = await Promise.all(
|
const enhancedComments = await Promise.all(
|
||||||
userComments.map(async (record) => {
|
userComments.map(async (record) => {
|
||||||
if (record.value.author?.handle) {
|
if (!record.value.author?.avatar && record.value.author?.handle) {
|
||||||
try {
|
try {
|
||||||
// Use existing PDS detection logic
|
const profile = await agent.getProfile({ actor: record.value.author.handle });
|
||||||
const handle = record.value.author.handle;
|
|
||||||
const pds = detectPdsFromHandle(handle);
|
|
||||||
const config = getNetworkConfigFromPdsEndpoint(`https://${pds}`);
|
|
||||||
const apiEndpoint = config.bskyApi;
|
|
||||||
|
|
||||||
const profileResponse = await fetch(`${apiEndpoint}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`);
|
|
||||||
if (profileResponse.ok) {
|
|
||||||
const profileData = await profileResponse.json();
|
|
||||||
return {
|
return {
|
||||||
...record,
|
...record,
|
||||||
value: {
|
value: {
|
||||||
...record.value,
|
...record.value,
|
||||||
author: {
|
author: {
|
||||||
...record.value.author,
|
...record.value.author,
|
||||||
avatar: profileData.avatar,
|
avatar: profile.data.avatar,
|
||||||
displayName: profileData.displayName || handle,
|
displayName: profile.data.displayName || record.value.author.handle,
|
||||||
_pdsEndpoint: `https://${pds}`, // Store PDS info for later use
|
|
||||||
_webUrl: config.webUrl, // Store web URL for profile links
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
// If profile fetch fails, still add PDS info for links
|
|
||||||
return {
|
|
||||||
...record,
|
|
||||||
value: {
|
|
||||||
...record.value,
|
|
||||||
author: {
|
|
||||||
...record.value.author,
|
|
||||||
_pdsEndpoint: `https://${pds}`,
|
|
||||||
_webUrl: config.webUrl,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore enhancement errors, use existing data
|
// Ignore enhancement errors
|
||||||
|
return record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return record;
|
return record;
|
||||||
@@ -572,34 +389,23 @@ function App() {
|
|||||||
// JSONからユーザーリストを取得
|
// JSONからユーザーリストを取得
|
||||||
const loadUsersFromRecord = async () => {
|
const loadUsersFromRecord = async () => {
|
||||||
try {
|
try {
|
||||||
// 管理者のユーザーリストを取得 using proper PDS detection
|
// 管理者のユーザーリストを取得
|
||||||
const currentAdminDid = adminDid || appConfig.adminDid;
|
const adminDid = appConfig.adminDid;
|
||||||
|
// Fetching user list from admin DID
|
||||||
// Use per-user PDS detection for admin's records
|
const response = await fetch(`https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(getCollectionNames(appConfig.collections.base).user)}&limit=100`);
|
||||||
let adminPdsEndpoint;
|
|
||||||
try {
|
|
||||||
const resolved = await import('./utils/pds-detection').then(m => m.resolvePdsFromRepo(currentAdminDid));
|
|
||||||
const config = await import('./utils/pds-detection').then(m => m.getNetworkConfigFromPdsEndpoint(resolved.pds));
|
|
||||||
adminPdsEndpoint = config.pdsApi;
|
|
||||||
} catch {
|
|
||||||
adminPdsEndpoint = 'https://bsky.social'; // Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
const userCollectionUrl = `${adminPdsEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(currentAdminDid)}&collection=${encodeURIComponent(getCollectionNames(appConfig.collections.base).user)}&limit=100`;
|
|
||||||
|
|
||||||
const response = await fetch(userCollectionUrl);
|
|
||||||
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
// Failed to fetch user list from admin, using default users
|
||||||
return getDefaultUsers();
|
return getDefaultUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const userRecords = data.records || [];
|
const userRecords = data.records || [];
|
||||||
|
// User records found
|
||||||
|
|
||||||
if (userRecords.length === 0) {
|
if (userRecords.length === 0) {
|
||||||
const defaultUsers = getDefaultUsers();
|
// No user records found, using default users
|
||||||
return defaultUsers;
|
return getDefaultUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// レコードからユーザーリストを構築し、プレースホルダーDIDを実際のDIDに解決
|
// レコードからユーザーリストを構築し、プレースホルダーDIDを実際のDIDに解決
|
||||||
@@ -610,16 +416,19 @@ function App() {
|
|||||||
const resolvedUsers = await Promise.all(
|
const resolvedUsers = await Promise.all(
|
||||||
record.value.users.map(async (user) => {
|
record.value.users.map(async (user) => {
|
||||||
if (user.did && user.did.includes('-placeholder')) {
|
if (user.did && user.did.includes('-placeholder')) {
|
||||||
// Resolving placeholder DID using proper PDS detection
|
// Resolving placeholder DID
|
||||||
try {
|
try {
|
||||||
const profile = await import('./utils/pds-detection').then(m => m.getProfileForUser(user.handle));
|
const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`);
|
||||||
if (profile && profile.did) {
|
if (profileResponse.ok) {
|
||||||
|
const profileData = await profileResponse.json();
|
||||||
|
if (profileData.did) {
|
||||||
// Resolved DID
|
// Resolved DID
|
||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
did: profile.did
|
did: profileData.did
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Failed to resolve DID
|
// Failed to resolve DID
|
||||||
}
|
}
|
||||||
@@ -631,6 +440,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loaded and resolved users from admin records
|
||||||
return allUsers;
|
return allUsers;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Failed to load users from records, using defaults
|
// Failed to load users from records, using defaults
|
||||||
@@ -641,20 +451,9 @@ function App() {
|
|||||||
// ユーザーリスト一覧を読み込み
|
// ユーザーリスト一覧を読み込み
|
||||||
const loadUserListRecords = async () => {
|
const loadUserListRecords = async () => {
|
||||||
try {
|
try {
|
||||||
// Loading user list records using proper PDS detection
|
// Loading user list records
|
||||||
const currentAdminDid = adminDid || appConfig.adminDid;
|
const adminDid = appConfig.adminDid;
|
||||||
|
const response = await fetch(`https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(adminDid)}&collection=${encodeURIComponent(getCollectionNames(appConfig.collections.base).user)}&limit=100`);
|
||||||
// Use per-user PDS detection for admin's records
|
|
||||||
let adminPdsEndpoint;
|
|
||||||
try {
|
|
||||||
const resolved = await import('./utils/pds-detection').then(m => m.resolvePdsFromRepo(currentAdminDid));
|
|
||||||
const config = await import('./utils/pds-detection').then(m => m.getNetworkConfigFromPdsEndpoint(resolved.pds));
|
|
||||||
adminPdsEndpoint = config.pdsApi;
|
|
||||||
} catch {
|
|
||||||
adminPdsEndpoint = 'https://bsky.social'; // Fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${adminPdsEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(currentAdminDid)}&collection=${encodeURIComponent(getCollectionNames(appConfig.collections.base).user)}&limit=100`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
// Failed to fetch user list records
|
// Failed to fetch user list records
|
||||||
@@ -679,26 +478,21 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getDefaultUsers = () => {
|
const getDefaultUsers = () => {
|
||||||
const currentAdminDid = adminDid || appConfig.adminDid;
|
|
||||||
const defaultUsers = [
|
const defaultUsers = [
|
||||||
// Default admin user
|
// Default admin user
|
||||||
{ did: currentAdminDid, handle: appConfig.adminHandle, pds: 'https://syu.is' },
|
{ did: appConfig.adminDid, handle: 'syui.ai', pds: 'https://bsky.social' },
|
||||||
];
|
];
|
||||||
|
|
||||||
// 現在ログインしているユーザーも追加(重複チェック)
|
// 現在ログインしているユーザーも追加(重複チェック)
|
||||||
if (user && user.did && user.handle && !defaultUsers.find(u => u.did === user.did)) {
|
if (user && user.did && user.handle && !defaultUsers.find(u => u.did === user.did)) {
|
||||||
// Detect PDS based on handle
|
|
||||||
const userPds = user.handle.endsWith('.syu.is') ? 'https://syu.is' :
|
|
||||||
user.handle.endsWith('.syui.ai') ? 'https://syu.is' :
|
|
||||||
'https://bsky.social';
|
|
||||||
|
|
||||||
defaultUsers.push({
|
defaultUsers.push({
|
||||||
did: user.did,
|
did: user.did,
|
||||||
handle: user.handle,
|
handle: user.handle,
|
||||||
pds: userPds
|
pds: user.handle.endsWith('.syu.is') ? 'https://syu.is' : 'https://bsky.social'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default users list (including current user)
|
||||||
return defaultUsers;
|
return defaultUsers;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -715,19 +509,9 @@ function App() {
|
|||||||
for (const user of knownUsers) {
|
for (const user of knownUsers) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Use per-user PDS detection for repo operations
|
// Public API使用(認証不要)
|
||||||
let pdsEndpoint;
|
|
||||||
try {
|
|
||||||
const resolved = await import('./utils/pds-detection').then(m => m.resolvePdsFromRepo(user.did));
|
|
||||||
const config = await import('./utils/pds-detection').then(m => m.getNetworkConfigFromPdsEndpoint(resolved.pds));
|
|
||||||
pdsEndpoint = config.pdsApi;
|
|
||||||
} catch {
|
|
||||||
// Fallback to user.pds if PDS detection fails
|
|
||||||
pdsEndpoint = user.pds;
|
|
||||||
}
|
|
||||||
|
|
||||||
const collections = getCollectionNames(appConfig.collections.base);
|
const collections = getCollectionNames(appConfig.collections.base);
|
||||||
const response = await fetch(`${pdsEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(user.did)}&collection=${encodeURIComponent(collections.comment)}&limit=100`);
|
const response = await fetch(`${user.pds}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(user.did)}&collection=${encodeURIComponent(collections.comment)}&limit=100`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
continue;
|
continue;
|
||||||
@@ -756,14 +540,16 @@ function App() {
|
|||||||
|
|
||||||
|
|
||||||
// ページpathでフィルタリング(指定された場合)
|
// ページpathでフィルタリング(指定された場合)
|
||||||
const filteredComments = pageUrl && appConfig.rkey
|
const filteredComments = pageUrl
|
||||||
? userComments.filter(record => {
|
? userComments.filter(record => {
|
||||||
try {
|
try {
|
||||||
// Compare rkey only (last part of path)
|
// Compare path only, not full URL to support localhost vs production
|
||||||
const recordRkey = record.value.url ? new URL(record.value.url).pathname.split('/').pop() : '';
|
const recordPath = record.value.url ? new URL(record.value.url).pathname : '';
|
||||||
return recordRkey === appConfig.rkey;
|
const currentPath = new URL(pageUrl).pathname;
|
||||||
|
return recordPath === currentPath;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return false;
|
// Fallback to exact match if URL parsing fails
|
||||||
|
return record.value.url === pageUrl;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
: userComments;
|
: userComments;
|
||||||
@@ -783,18 +569,19 @@ function App() {
|
|||||||
sortedComments.map(async (record) => {
|
sortedComments.map(async (record) => {
|
||||||
if (!record.value.author?.avatar && record.value.author?.handle) {
|
if (!record.value.author?.avatar && record.value.author?.handle) {
|
||||||
try {
|
try {
|
||||||
// Use per-user PDS detection for profile fetching
|
// Public API でプロフィール取得
|
||||||
const profile = await import('./utils/pds-detection').then(m => m.getProfileForUser(record.value.author.handle));
|
const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`);
|
||||||
|
|
||||||
if (profile) {
|
if (profileResponse.ok) {
|
||||||
|
const profileData = await profileResponse.json();
|
||||||
return {
|
return {
|
||||||
...record,
|
...record,
|
||||||
value: {
|
value: {
|
||||||
...record.value,
|
...record.value,
|
||||||
author: {
|
author: {
|
||||||
...record.value.author,
|
...record.value.author,
|
||||||
avatar: profile.avatar,
|
avatar: profileData.avatar,
|
||||||
displayName: profile.displayName || record.value.author.handle,
|
displayName: profileData.displayName || record.value.author.handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -961,7 +748,7 @@ function App() {
|
|||||||
|
|
||||||
// 管理者チェック
|
// 管理者チェック
|
||||||
const isAdmin = (user: User | null): boolean => {
|
const isAdmin = (user: User | null): boolean => {
|
||||||
return user?.did === adminDid || user?.did === appConfig.adminDid;
|
return user?.did === appConfig.adminDid;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ユーザーリスト投稿
|
// ユーザーリスト投稿
|
||||||
@@ -1110,25 +897,12 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ユーザーハンドルからプロフィールURLを生成
|
// ユーザーハンドルからプロフィールURLを生成
|
||||||
const generateProfileUrl = (author: any): string => {
|
const generateProfileUrl = (handle: string, did: string): string => {
|
||||||
// Check if this is admin/AI handle that should use configured PDS
|
if (handle.endsWith('.syu.is')) {
|
||||||
if (author.handle === appConfig.adminHandle || author.handle === appConfig.aiHandle) {
|
return `https://web.syu.is/profile/${did}`;
|
||||||
const config = getNetworkConfig(appConfig.atprotoPds);
|
} else {
|
||||||
return `${config.webUrl}/profile/${author.did}`;
|
return `https://bsky.app/profile/${did}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For ai.syu.is handle, also use configured PDS
|
|
||||||
if (author.handle === 'ai.syu.is') {
|
|
||||||
const config = getNetworkConfig(appConfig.atprotoPds);
|
|
||||||
return `${config.webUrl}/profile/${author.did}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get PDS from handle for other users
|
|
||||||
const pds = detectPdsFromHandle(author.handle);
|
|
||||||
const config = getNetworkConfig(pds);
|
|
||||||
|
|
||||||
// Use DID for profile URL
|
|
||||||
return `${config.webUrl}/profile/${author.did}`;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Rkey-based comment filtering
|
// Rkey-based comment filtering
|
||||||
@@ -1163,8 +937,7 @@ function App() {
|
|||||||
|
|
||||||
// Extract content based on format
|
// Extract content based on format
|
||||||
const contentText = isNewFormat ? value.text : (value.content || value.body || '');
|
const contentText = isNewFormat ? value.text : (value.content || value.body || '');
|
||||||
// For AI comments, always use the loaded AI profile instead of record.value.author
|
const authorInfo = isNewFormat ? value.author : null;
|
||||||
const authorInfo = aiProfile;
|
|
||||||
const postInfo = isNewFormat ? value.post : null;
|
const postInfo = isNewFormat ? value.post : null;
|
||||||
const contentType = value.type || 'unknown';
|
const contentType = value.type || 'unknown';
|
||||||
const createdAt = value.createdAt || value.generated_at || '';
|
const createdAt = value.createdAt || value.generated_at || '';
|
||||||
@@ -1176,22 +949,29 @@ function App() {
|
|||||||
src={authorInfo?.avatar || generatePlaceholderAvatar('AI')}
|
src={authorInfo?.avatar || generatePlaceholderAvatar('AI')}
|
||||||
alt="AI Avatar"
|
alt="AI Avatar"
|
||||||
className="comment-avatar"
|
className="comment-avatar"
|
||||||
|
ref={(img) => {
|
||||||
|
// For old format, try to fetch from ai_did
|
||||||
|
if (img && !isNewFormat && value.ai_did) {
|
||||||
|
fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(value.ai_did)}`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.avatar && img) {
|
||||||
|
img.src = data.avatar;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
// Keep placeholder on error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="comment-author-info">
|
<div className="comment-author-info">
|
||||||
<span className="comment-author">
|
<span className="comment-author">
|
||||||
{authorInfo?.displayName || 'ai'}
|
{authorInfo?.displayName || 'AI'}
|
||||||
|
</span>
|
||||||
|
<span className="comment-handle">
|
||||||
|
@{authorInfo?.handle || 'ai'}
|
||||||
</span>
|
</span>
|
||||||
<a
|
|
||||||
href={generateProfileUrl({
|
|
||||||
handle: authorInfo?.handle || aiProfile?.handle || appConfig.aiHandle,
|
|
||||||
did: authorInfo?.did || aiProfile?.did || appConfig.aiDid
|
|
||||||
})}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="comment-handle"
|
|
||||||
>
|
|
||||||
@{authorInfo?.handle || aiProfile?.handle || appConfig.aiHandle}
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
<span className="comment-date">
|
<span className="comment-date">
|
||||||
{new Date(createdAt).toLocaleString()}
|
{new Date(createdAt).toLocaleString()}
|
||||||
@@ -1263,11 +1043,16 @@ function App() {
|
|||||||
<section className="comment-section">
|
<section className="comment-section">
|
||||||
{/* Authentication Section */}
|
{/* Authentication Section */}
|
||||||
{!user ? (
|
{!user ? (
|
||||||
<div className="auth-section search-bar-layout">
|
<div className="auth-section">
|
||||||
|
<button
|
||||||
|
onClick={executeOAuth}
|
||||||
|
className="atproto-button"
|
||||||
|
>
|
||||||
|
atproto
|
||||||
|
</button>
|
||||||
|
<div className="username-input-section">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="handle-input"
|
|
||||||
name="handle"
|
|
||||||
placeholder="user.bsky.social"
|
placeholder="user.bsky.social"
|
||||||
className="handle-input"
|
className="handle-input"
|
||||||
value={handleInput}
|
value={handleInput}
|
||||||
@@ -1279,12 +1064,7 @@ function App() {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
</div>
|
||||||
onClick={executeOAuth}
|
|
||||||
className="atproto-button"
|
|
||||||
>
|
|
||||||
<i class="fab fa-bluesky"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="user-section">
|
<div className="user-section">
|
||||||
@@ -1314,11 +1094,9 @@ function App() {
|
|||||||
{/* User List Form */}
|
{/* User List Form */}
|
||||||
<div className="user-list-form">
|
<div className="user-list-form">
|
||||||
<textarea
|
<textarea
|
||||||
id="user-list-input"
|
|
||||||
name="userList"
|
|
||||||
value={userListInput}
|
value={userListInput}
|
||||||
onChange={(e) => setUserListInput(e.target.value)}
|
onChange={(e) => setUserListInput(e.target.value)}
|
||||||
placeholder="ユーザーハンドルをカンマ区切りで入力 例: syui.ai, ai.syui.ai, user.bsky.social"
|
placeholder="ユーザーハンドルをカンマ区切りで入力 例: syui.ai, yui.syui.ai, user.bsky.social"
|
||||||
rows={3}
|
rows={3}
|
||||||
disabled={isPostingUserList}
|
disabled={isPostingUserList}
|
||||||
/>
|
/>
|
||||||
@@ -1404,25 +1182,25 @@ function App() {
|
|||||||
className={`tab-button ${activeTab === 'comments' ? 'active' : ''}`}
|
className={`tab-button ${activeTab === 'comments' ? 'active' : ''}`}
|
||||||
onClick={() => setActiveTab('comments')}
|
onClick={() => setActiveTab('comments')}
|
||||||
>
|
>
|
||||||
comment ({comments.filter(shouldShowComment).length})
|
Comments ({comments.filter(shouldShowComment).length})
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`tab-button ${activeTab === 'ai-chat' ? 'active' : ''}`}
|
className={`tab-button ${activeTab === 'ai-chat' ? 'active' : ''}`}
|
||||||
onClick={() => setActiveTab('ai-chat')}
|
onClick={() => setActiveTab('ai-chat')}
|
||||||
>
|
>
|
||||||
chat ({aiChatHistory.length})
|
AI Chat History ({aiChatHistory.length})
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`tab-button ${activeTab === 'lang-en' ? 'active' : ''}`}
|
className={`tab-button ${activeTab === 'lang-en' ? 'active' : ''}`}
|
||||||
onClick={() => setActiveTab('lang-en')}
|
onClick={() => setActiveTab('lang-en')}
|
||||||
>
|
>
|
||||||
en ({langEnRecords.length})
|
Lang: EN ({langEnRecords.length})
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`tab-button ${activeTab === 'ai-comment' ? 'active' : ''}`}
|
className={`tab-button ${activeTab === 'ai-comment' ? 'active' : ''}`}
|
||||||
onClick={() => setActiveTab('ai-comment')}
|
onClick={() => setActiveTab('ai-comment')}
|
||||||
>
|
>
|
||||||
feedback ({aiCommentRecords.length})
|
AI Comment ({aiCommentRecords.length})
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1438,16 +1216,31 @@ function App() {
|
|||||||
<div key={index} className="comment-item">
|
<div key={index} className="comment-item">
|
||||||
<div className="comment-header">
|
<div className="comment-header">
|
||||||
<img
|
<img
|
||||||
src={record.value.author?.avatar || generatePlaceholderAvatar(record.value.author?.handle || 'unknown')}
|
src={generatePlaceholderAvatar(record.value.author?.handle || 'unknown')}
|
||||||
alt="User Avatar"
|
alt="User Avatar"
|
||||||
className="comment-avatar"
|
className="comment-avatar"
|
||||||
|
ref={(img) => {
|
||||||
|
// Fetch fresh avatar from API when component mounts
|
||||||
|
if (img && record.value.author?.did) {
|
||||||
|
fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.did)}`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.avatar && img) {
|
||||||
|
img.src = data.avatar;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
// Keep placeholder on error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="comment-author-info">
|
<div className="comment-author-info">
|
||||||
<span className="comment-author">
|
<span className="comment-author">
|
||||||
{record.value.author?.displayName || record.value.author?.handle || 'unknown'}
|
{record.value.author?.displayName || record.value.author?.handle || 'unknown'}
|
||||||
</span>
|
</span>
|
||||||
<a
|
<a
|
||||||
href={generateProfileUrl(record.value.author)}
|
href={generateProfileUrl(record.value.author?.handle || '', record.value.author?.did || '')}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="comment-handle"
|
className="comment-handle"
|
||||||
@@ -1511,22 +1304,109 @@ function App() {
|
|||||||
|
|
||||||
{/* AI Chat History List */}
|
{/* AI Chat History List */}
|
||||||
{activeTab === 'ai-chat' && (
|
{activeTab === 'ai-chat' && (
|
||||||
<div className="comments-list">
|
<div className="ai-chat-list">
|
||||||
|
<div className="chat-header">
|
||||||
|
<h3>AI Chat History</h3>
|
||||||
|
</div>
|
||||||
{aiChatHistory.length === 0 ? (
|
{aiChatHistory.length === 0 ? (
|
||||||
<p className="no-chat">No AI conversations yet. Start chatting with Ask AI!</p>
|
<p className="no-chat">No AI conversations yet. Start chatting with Ask AI!</p>
|
||||||
) : (
|
) : (
|
||||||
aiChatHistory.map((record, index) =>
|
aiChatHistory.map((record, index) => {
|
||||||
renderAIContent(record, index, 'comment-item')
|
// For AI responses, use AI DID; for user questions, use the actual author
|
||||||
)
|
const isAiResponse = record.value.type === 'answer';
|
||||||
|
const displayDid = isAiResponse ? appConfig.aiDid : record.value.author?.did;
|
||||||
|
const displayHandle = isAiResponse ? 'ai.syui' : record.value.author?.handle;
|
||||||
|
const displayName = isAiResponse ? 'AI' : (record.value.author?.displayName || record.value.author?.handle);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={index} className="chat-item">
|
||||||
|
<div className="chat-header">
|
||||||
|
<img
|
||||||
|
src={generatePlaceholderAvatar(displayHandle || 'unknown')}
|
||||||
|
alt={isAiResponse ? "AI Avatar" : "User Avatar"}
|
||||||
|
className="comment-avatar"
|
||||||
|
ref={(img) => {
|
||||||
|
// Fetch fresh avatar from API when component mounts
|
||||||
|
if (img && displayDid) {
|
||||||
|
fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(displayDid)}`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.avatar && img) {
|
||||||
|
img.src = data.avatar;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
// Keep placeholder on error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="comment-author-info">
|
||||||
|
<span className="comment-author">
|
||||||
|
{displayName || 'unknown'}
|
||||||
|
</span>
|
||||||
|
<a
|
||||||
|
href={generateProfileUrl(displayHandle || '', displayDid || '')}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="comment-handle"
|
||||||
|
>
|
||||||
|
@{displayHandle || 'unknown'}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<span className="comment-date">
|
||||||
|
{new Date(record.value.createdAt).toLocaleString()}
|
||||||
|
</span>
|
||||||
|
<div className="comment-actions">
|
||||||
|
<button
|
||||||
|
onClick={() => toggleJsonDisplay(record.uri)}
|
||||||
|
className="json-button"
|
||||||
|
title="Show/Hide JSON"
|
||||||
|
>
|
||||||
|
{showJsonFor === record.uri ? 'Hide' : 'JSON'}
|
||||||
|
</button>
|
||||||
|
<button className="chat-type-button">
|
||||||
|
{record.value.type === 'question' ? 'Question' : 'Answer'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="comment-meta">
|
||||||
|
{record.value.post?.url && (
|
||||||
|
<small><a href={record.value.post.url}>{record.value.post.url}</a></small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* JSON Display */}
|
||||||
|
{showJsonFor === record.uri && (
|
||||||
|
<div className="json-display">
|
||||||
|
<h5>JSON Record:</h5>
|
||||||
|
<pre className="json-content">
|
||||||
|
{JSON.stringify(record, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="comment-content">
|
||||||
|
{record.value.text?.split('\n').map((line: string, index: number) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
{line}
|
||||||
|
{index < record.value.text.split('\n').length - 1 && <br />}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Lang: EN List */}
|
{/* Lang: EN List */}
|
||||||
{activeTab === 'lang-en' && (
|
{activeTab === 'lang-en' && (
|
||||||
<div className="comments-list">
|
<div className="lang-en-list">
|
||||||
{langEnRecords.length === 0 ? (
|
{langEnRecords.length === 0 ? (
|
||||||
<p className="no-content">No EN translations yet</p>
|
<p className="no-content">No English translations yet</p>
|
||||||
) : (
|
) : (
|
||||||
langEnRecords.map((record, index) =>
|
langEnRecords.map((record, index) =>
|
||||||
renderAIContent(record, index, 'lang-item')
|
renderAIContent(record, index, 'lang-item')
|
||||||
@@ -1541,19 +1421,86 @@ function App() {
|
|||||||
{aiCommentRecords.length === 0 ? (
|
{aiCommentRecords.length === 0 ? (
|
||||||
<p className="no-content">No AI comments yet</p>
|
<p className="no-content">No AI comments yet</p>
|
||||||
) : (
|
) : (
|
||||||
aiCommentRecords.map((record, index) =>
|
aiCommentRecords.map((record, index) => (
|
||||||
renderAIContent(record, index, 'comment-item')
|
<div key={index} className="comment-item">
|
||||||
)
|
<div className="comment-header">
|
||||||
|
<img
|
||||||
|
src={generatePlaceholderAvatar('ai')}
|
||||||
|
alt="AI Avatar"
|
||||||
|
className="comment-avatar"
|
||||||
|
ref={(img) => {
|
||||||
|
// Fetch AI avatar
|
||||||
|
if (img && appConfig.aiDid) {
|
||||||
|
fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(appConfig.aiDid)}`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.avatar && img) {
|
||||||
|
img.src = data.avatar;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
// Keep placeholder on error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="comment-author-info">
|
||||||
|
<span className="comment-author">
|
||||||
|
AI
|
||||||
|
</span>
|
||||||
|
<span className="comment-handle">
|
||||||
|
@ai
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="comment-date">
|
||||||
|
{new Date(record.value.createdAt || record.value.generated_at).toLocaleString()}
|
||||||
|
</span>
|
||||||
|
<div className="comment-actions">
|
||||||
|
<button
|
||||||
|
onClick={() => toggleJsonDisplay(record.uri)}
|
||||||
|
className="json-button"
|
||||||
|
title="Show/Hide JSON"
|
||||||
|
>
|
||||||
|
{showJsonFor === record.uri ? 'Hide' : 'JSON'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="comment-meta">
|
||||||
|
{(record.value.post?.url || record.value.post_url) && (
|
||||||
|
<small><a href={record.value.post?.url || record.value.post_url}>{record.value.post?.url || record.value.post_url}</a></small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* JSON Display */}
|
||||||
|
{showJsonFor === record.uri && (
|
||||||
|
<div className="json-display">
|
||||||
|
<h5>JSON Record:</h5>
|
||||||
|
<pre className="json-content">
|
||||||
|
{JSON.stringify(record, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="comment-content">
|
||||||
|
{(record.value.text || record.value.comment)?.split('\n').map((line: string, index: number) => (
|
||||||
|
<React.Fragment key={index}>
|
||||||
|
{line}
|
||||||
|
{index < (record.value.text || record.value.comment)?.split('\n').length - 1 && <br />}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Comment Form - Only show on post pages when Comments tab is active */}
|
{/* Comment Form - Only show on post pages */}
|
||||||
{user && appConfig.rkey && activeTab === 'comments' && (
|
{user && appConfig.rkey && (
|
||||||
<div className="comment-form">
|
<div className="comment-form">
|
||||||
|
<h3>Post a Comment</h3>
|
||||||
<textarea
|
<textarea
|
||||||
id="comment-text"
|
|
||||||
name="commentText"
|
|
||||||
value={commentText}
|
value={commentText}
|
||||||
onChange={(e) => setCommentText(e.target.value)}
|
onChange={(e) => setCommentText(e.target.value)}
|
||||||
placeholder="Write your comment..."
|
placeholder="Write your comment..."
|
||||||
@@ -1574,6 +1521,13 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Show authentication status on non-post pages */}
|
||||||
|
{user && !appConfig.rkey && (
|
||||||
|
<div className="auth-status">
|
||||||
|
<p>✅ Authenticated as @{user.handle}</p>
|
||||||
|
<p><small>Visit a post page to comment</small></p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ const response = await fetch(`${aiConfig.host}/api/generate`, {
|
|||||||
options: {
|
options: {
|
||||||
temperature: 0.9,
|
temperature: 0.9,
|
||||||
top_p: 0.9,
|
top_p: 0.9,
|
||||||
num_predict: 200,
|
num_predict: 80,
|
||||||
repeat_penalty: 1.1,
|
repeat_penalty: 1.1,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@@ -199,7 +199,7 @@ Answer:`;
|
|||||||
options: {
|
options: {
|
||||||
temperature: 0.9,
|
temperature: 0.9,
|
||||||
top_p: 0.9,
|
top_p: 0.9,
|
||||||
num_predict: 200, // Longer responses for better answers
|
num_predict: 80, // Shorter responses for faster generation
|
||||||
repeat_penalty: 1.1,
|
repeat_penalty: 1.1,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@@ -32,7 +32,7 @@ export const AIProfile: React.FC<AIProfileProps> = ({ aiDid }) => {
|
|||||||
description: response.data.description,
|
description: response.data.description,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Failed to fetch AI profile
|
console.error('Failed to fetch AI profile:', error);
|
||||||
// Fallback to basic info
|
// Fallback to basic info
|
||||||
setProfile({
|
setProfile({
|
||||||
did: aiDid,
|
did: aiDid,
|
||||||
|
@@ -26,7 +26,7 @@ export const CardBox: React.FC<CardBoxProps> = ({ userDid }) => {
|
|||||||
const data = await atprotoOAuthService.getCardsFromBox();
|
const data = await atprotoOAuthService.getCardsFromBox();
|
||||||
setBoxData(data);
|
setBoxData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Failed to load card box
|
console.error('カードボックス読み込みエラー:', err);
|
||||||
setError(err instanceof Error ? err.message : 'カードボックスの読み込みに失敗しました');
|
setError(err instanceof Error ? err.message : 'カードボックスの読み込みに失敗しました');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -52,7 +52,7 @@ export const CardBox: React.FC<CardBoxProps> = ({ userDid }) => {
|
|||||||
setBoxData({ records: [] });
|
setBoxData({ records: [] });
|
||||||
alert('カードボックスを削除しました');
|
alert('カードボックスを削除しました');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Failed to delete card box
|
console.error('カードボックス削除エラー:', err);
|
||||||
setError(err instanceof Error ? err.message : 'カードボックスの削除に失敗しました');
|
setError(err instanceof Error ? err.message : 'カードボックスの削除に失敗しました');
|
||||||
} finally {
|
} finally {
|
||||||
setIsDeleting(false);
|
setIsDeleting(false);
|
||||||
|
@@ -32,7 +32,7 @@ export const CardList: React.FC = () => {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setMasterData(data);
|
setMasterData(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Failed to load card master data
|
console.error('Error loading card master data:', err);
|
||||||
setError(err instanceof Error ? err.message : 'Failed to load card data');
|
setError(err instanceof Error ? err.message : 'Failed to load card data');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
@@ -29,7 +29,7 @@ export const CollectionAnalysis: React.FC<CollectionAnalysisProps> = ({ userDid
|
|||||||
const result = await aiCardApi.analyzeCollection(userDid);
|
const result = await aiCardApi.analyzeCollection(userDid);
|
||||||
setAnalysis(result);
|
setAnalysis(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Collection analysis failed
|
console.error('Collection analysis failed:', err);
|
||||||
setError('AI分析機能を利用するにはai.gptサーバーが必要です。基本機能はai.cardサーバーのみで利用できます。');
|
setError('AI分析機能を利用するにはai.gptサーバーが必要です。基本機能はai.cardサーバーのみで利用できます。');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
@@ -48,7 +48,7 @@ export const GachaAnimation: React.FC<GachaAnimationProps> = ({
|
|||||||
await atprotoOAuthService.saveCardToCollection(card);
|
await atprotoOAuthService.saveCardToCollection(card);
|
||||||
alert('カードデータをatprotoコレクションに保存しました!');
|
alert('カードデータをatprotoコレクションに保存しました!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Failed to save card
|
console.error('保存エラー:', error);
|
||||||
alert('保存に失敗しました。認証が必要かもしれません。');
|
alert('保存に失敗しました。認証が必要かもしれません。');
|
||||||
} finally {
|
} finally {
|
||||||
setIsSharing(false);
|
setIsSharing(false);
|
||||||
|
@@ -30,7 +30,7 @@ export const GachaStats: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
result = await aiCardApi.getEnhancedStats();
|
result = await aiCardApi.getEnhancedStats();
|
||||||
} catch (aiError) {
|
} catch (aiError) {
|
||||||
// AI stats unavailable, using basic stats
|
console.warn('AI統計が利用できません、基本統計に切り替えます:', aiError);
|
||||||
setUseAI(false);
|
setUseAI(false);
|
||||||
result = await cardApi.getGachaStats();
|
result = await cardApi.getGachaStats();
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ export const GachaStats: React.FC = () => {
|
|||||||
}
|
}
|
||||||
setStats(result);
|
setStats(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Gacha stats failed
|
console.error('Gacha stats failed:', err);
|
||||||
setError('統計データの取得に失敗しました。ai.cardサーバーが起動していることを確認してください。');
|
setError('統計データの取得に失敗しました。ai.cardサーバーが起動していることを確認してください。');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
@@ -160,7 +160,7 @@ export const Login: React.FC<LoginProps> = ({ onLogin, onClose, defaultHandle })
|
|||||||
/>
|
/>
|
||||||
<small>
|
<small>
|
||||||
メインパスワードではなく、
|
メインパスワードではなく、
|
||||||
<a href={`${import.meta.env.VITE_ATPROTO_WEB_URL || 'https://bsky.app'}/settings/app-passwords`} target="_blank" rel="noopener noreferrer">
|
<a href="https://bsky.app/settings/app-passwords" target="_blank" rel="noopener noreferrer">
|
||||||
アプリパスワード
|
アプリパスワード
|
||||||
</a>
|
</a>
|
||||||
を使用してください
|
を使用してください
|
||||||
|
@@ -7,6 +7,8 @@ interface OAuthCallbackProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError }) => {
|
export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError }) => {
|
||||||
|
console.log('=== OAUTH CALLBACK COMPONENT MOUNTED ===');
|
||||||
|
console.log('Current URL:', window.location.href);
|
||||||
|
|
||||||
const [isProcessing, setIsProcessing] = useState(true);
|
const [isProcessing, setIsProcessing] = useState(true);
|
||||||
const [needsHandle, setNeedsHandle] = useState(false);
|
const [needsHandle, setNeedsHandle] = useState(false);
|
||||||
@@ -16,10 +18,12 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Add timeout to prevent infinite loading
|
// Add timeout to prevent infinite loading
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
|
console.error('OAuth callback timeout');
|
||||||
onError('OAuth認証がタイムアウトしました');
|
onError('OAuth認証がタイムアウトしました');
|
||||||
}, 10000); // 10 second timeout
|
}, 10000); // 10 second timeout
|
||||||
|
|
||||||
const handleCallback = async () => {
|
const handleCallback = async () => {
|
||||||
|
console.log('=== HANDLE CALLBACK STARTED ===');
|
||||||
try {
|
try {
|
||||||
// Handle both query params (?) and hash params (#)
|
// Handle both query params (?) and hash params (#)
|
||||||
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
||||||
@@ -31,6 +35,14 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
const error = hashParams.get('error') || queryParams.get('error');
|
const error = hashParams.get('error') || queryParams.get('error');
|
||||||
const iss = hashParams.get('iss') || queryParams.get('iss');
|
const iss = hashParams.get('iss') || queryParams.get('iss');
|
||||||
|
|
||||||
|
console.log('OAuth callback parameters:', {
|
||||||
|
code: code ? code.substring(0, 20) + '...' : null,
|
||||||
|
state: state,
|
||||||
|
error: error,
|
||||||
|
iss: iss,
|
||||||
|
hash: window.location.hash,
|
||||||
|
search: window.location.search
|
||||||
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(`OAuth error: ${error}`);
|
throw new Error(`OAuth error: ${error}`);
|
||||||
@@ -40,10 +52,12 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
throw new Error('Missing OAuth parameters');
|
throw new Error('Missing OAuth parameters');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Processing OAuth callback with params:', { code: code?.substring(0, 10) + '...', state, iss });
|
||||||
|
|
||||||
// Use the official BrowserOAuthClient to handle the callback
|
// Use the official BrowserOAuthClient to handle the callback
|
||||||
const result = await atprotoOAuthService.handleOAuthCallback();
|
const result = await atprotoOAuthService.handleOAuthCallback();
|
||||||
if (result) {
|
if (result) {
|
||||||
|
console.log('OAuth callback completed successfully:', result);
|
||||||
|
|
||||||
// Success - notify parent component
|
// Success - notify parent component
|
||||||
onSuccess(result.did, result.handle);
|
onSuccess(result.did, result.handle);
|
||||||
@@ -52,7 +66,11 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('OAuth callback error:', error);
|
||||||
|
|
||||||
// Even if OAuth fails, try to continue with a fallback approach
|
// Even if OAuth fails, try to continue with a fallback approach
|
||||||
|
console.warn('OAuth callback failed, attempting fallback...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create a minimal session to allow the user to proceed
|
// Create a minimal session to allow the user to proceed
|
||||||
const fallbackSession = {
|
const fallbackSession = {
|
||||||
@@ -64,6 +82,7 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
onSuccess(fallbackSession.did, fallbackSession.handle);
|
onSuccess(fallbackSession.did, fallbackSession.handle);
|
||||||
|
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
|
console.error('Fallback also failed:', fallbackError);
|
||||||
onError(error instanceof Error ? error.message : 'OAuth認証に失敗しました');
|
onError(error instanceof Error ? error.message : 'OAuth認証に失敗しました');
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -85,13 +104,17 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
|
|
||||||
const trimmedHandle = handle.trim();
|
const trimmedHandle = handle.trim();
|
||||||
if (!trimmedHandle) {
|
if (!trimmedHandle) {
|
||||||
|
console.log('Handle is empty');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Submitting handle:', trimmedHandle);
|
||||||
setIsProcessing(true);
|
setIsProcessing(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Resolve DID from handle
|
// Resolve DID from handle
|
||||||
const did = await atprotoOAuthService.resolveDIDFromHandle(trimmedHandle);
|
const did = await atprotoOAuthService.resolveDIDFromHandle(trimmedHandle);
|
||||||
|
console.log('Resolved DID:', did);
|
||||||
|
|
||||||
// Update session with resolved DID and handle
|
// Update session with resolved DID and handle
|
||||||
const updatedSession = {
|
const updatedSession = {
|
||||||
@@ -106,6 +129,7 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
// Success - notify parent component
|
// Success - notify parent component
|
||||||
onSuccess(did, trimmedHandle);
|
onSuccess(did, trimmedHandle);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Failed to resolve DID:', error);
|
||||||
setIsProcessing(false);
|
setIsProcessing(false);
|
||||||
onError(error instanceof Error ? error.message : 'ハンドルからDIDの解決に失敗しました');
|
onError(error instanceof Error ? error.message : 'ハンドルからDIDの解決に失敗しました');
|
||||||
}
|
}
|
||||||
@@ -125,6 +149,7 @@ export const OAuthCallback: React.FC<OAuthCallbackProps> = ({ onSuccess, onError
|
|||||||
type="text"
|
type="text"
|
||||||
value={handle}
|
value={handle}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
console.log('Input changed:', e.target.value);
|
||||||
setHandle(e.target.value);
|
setHandle(e.target.value);
|
||||||
}}
|
}}
|
||||||
placeholder="例: syui.ai または user.bsky.social"
|
placeholder="例: syui.ai または user.bsky.social"
|
||||||
|
@@ -6,9 +6,14 @@ export const OAuthCallbackPage: React.FC = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('=== OAUTH CALLBACK PAGE MOUNTED ===');
|
||||||
|
console.log('Current URL:', window.location.href);
|
||||||
|
console.log('Search params:', window.location.search);
|
||||||
|
console.log('Pathname:', window.location.pathname);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSuccess = (did: string, handle: string) => {
|
const handleSuccess = (did: string, handle: string) => {
|
||||||
|
console.log('OAuth success, redirecting to home:', { did, handle });
|
||||||
|
|
||||||
// Add a small delay to ensure state is properly updated
|
// Add a small delay to ensure state is properly updated
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -17,6 +22,7 @@ export const OAuthCallbackPage: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleError = (error: string) => {
|
const handleError = (error: string) => {
|
||||||
|
console.error('OAuth error, redirecting to home:', error);
|
||||||
|
|
||||||
// Add a small delay before redirect
|
// Add a small delay before redirect
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@@ -1,12 +1,7 @@
|
|||||||
// Application configuration
|
// Application configuration
|
||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
adminDid: string;
|
adminDid: string;
|
||||||
adminHandle: string;
|
|
||||||
aiDid: string;
|
aiDid: string;
|
||||||
aiHandle: string;
|
|
||||||
aiDisplayName: string;
|
|
||||||
aiAvatar: string;
|
|
||||||
aiDescription: string;
|
|
||||||
collections: {
|
collections: {
|
||||||
base: string; // Base collection like "ai.syui.log"
|
base: string; // Base collection like "ai.syui.log"
|
||||||
};
|
};
|
||||||
@@ -18,9 +13,6 @@ export interface AppConfig {
|
|||||||
aiModel: string;
|
aiModel: string;
|
||||||
aiHost: string;
|
aiHost: string;
|
||||||
aiSystemPrompt: string;
|
aiSystemPrompt: string;
|
||||||
allowedHandles: string[]; // Handles allowed for OAuth authentication
|
|
||||||
atprotoPds: string; // Configured PDS for admin/ai handles
|
|
||||||
// Legacy - prefer per-user PDS detection
|
|
||||||
bskyPublicApi: string;
|
bskyPublicApi: string;
|
||||||
atprotoApi: string;
|
atprotoApi: string;
|
||||||
}
|
}
|
||||||
@@ -70,29 +62,18 @@ function generateBaseCollectionFromHost(host: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract rkey from current URL
|
// Extract rkey from current URL
|
||||||
// /posts/xxx -> xxx (remove .html if present)
|
// /posts/xxx -> xxx
|
||||||
function extractRkeyFromUrl(): string | undefined {
|
function extractRkeyFromUrl(): string | undefined {
|
||||||
const pathname = window.location.pathname;
|
const pathname = window.location.pathname;
|
||||||
const match = pathname.match(/\/posts\/([^/]+)\/?$/);
|
const match = pathname.match(/\/posts\/([^/]+)\/?$/);
|
||||||
if (match) {
|
return match ? match[1] : undefined;
|
||||||
// Remove .html extension if present
|
|
||||||
return match[1].replace(/\.html$/, '');
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get application configuration from environment variables
|
// Get application configuration from environment variables
|
||||||
export function getAppConfig(): AppConfig {
|
export function getAppConfig(): AppConfig {
|
||||||
const host = import.meta.env.VITE_APP_HOST || 'https://log.syui.ai';
|
const host = import.meta.env.VITE_APP_HOST || 'https://log.syui.ai';
|
||||||
const adminHandle = import.meta.env.VITE_ADMIN_HANDLE || 'ai.syui.ai';
|
|
||||||
const aiHandle = import.meta.env.VITE_AI_HANDLE || 'ai.syui.ai';
|
|
||||||
|
|
||||||
// DIDsはハンドルから実行時に解決される(フォールバック用のみ保持)
|
|
||||||
const adminDid = import.meta.env.VITE_ADMIN_DID || 'did:plc:uqzpqmrjnptsxezjx4xuh2mn';
|
const adminDid = import.meta.env.VITE_ADMIN_DID || 'did:plc:uqzpqmrjnptsxezjx4xuh2mn';
|
||||||
const aiDid = import.meta.env.VITE_AI_DID || 'did:plc:6qyecktefllvenje24fcxnie';
|
const aiDid = import.meta.env.VITE_AI_DID || 'did:plc:4hqjfn7m6n5hno3doamuhgef';
|
||||||
const aiDisplayName = import.meta.env.VITE_AI_DISPLAY_NAME || 'ai';
|
|
||||||
const aiAvatar = import.meta.env.VITE_AI_AVATAR || '';
|
|
||||||
const aiDescription = import.meta.env.VITE_AI_DESCRIPTION || '';
|
|
||||||
|
|
||||||
// Priority: Environment variables > Auto-generated from host
|
// Priority: Environment variables > Auto-generated from host
|
||||||
const autoGeneratedBase = generateBaseCollectionFromHost(host);
|
const autoGeneratedBase = generateBaseCollectionFromHost(host);
|
||||||
@@ -116,28 +97,13 @@ export function getAppConfig(): AppConfig {
|
|||||||
const aiModel = import.meta.env.VITE_AI_MODEL || 'gemma2:2b';
|
const aiModel = import.meta.env.VITE_AI_MODEL || 'gemma2:2b';
|
||||||
const aiHost = import.meta.env.VITE_AI_HOST || 'https://ollama.syui.ai';
|
const aiHost = import.meta.env.VITE_AI_HOST || 'https://ollama.syui.ai';
|
||||||
const aiSystemPrompt = import.meta.env.VITE_AI_SYSTEM_PROMPT || 'You are a helpful AI assistant trained on this blog\'s content.';
|
const aiSystemPrompt = import.meta.env.VITE_AI_SYSTEM_PROMPT || 'You are a helpful AI assistant trained on this blog\'s content.';
|
||||||
const atprotoPds = import.meta.env.VITE_ATPROTO_PDS || 'syu.is';
|
|
||||||
const bskyPublicApi = import.meta.env.VITE_BSKY_PUBLIC_API || 'https://public.api.bsky.app';
|
const bskyPublicApi = import.meta.env.VITE_BSKY_PUBLIC_API || 'https://public.api.bsky.app';
|
||||||
const atprotoApi = import.meta.env.VITE_ATPROTO_API || 'https://bsky.social';
|
const atprotoApi = import.meta.env.VITE_ATPROTO_API || 'https://bsky.social';
|
||||||
|
|
||||||
// Parse allowed handles list
|
|
||||||
const allowedHandlesStr = import.meta.env.VITE_ATPROTO_HANDLE_LIST || '[]';
|
|
||||||
let allowedHandles: string[] = [];
|
|
||||||
try {
|
|
||||||
allowedHandles = JSON.parse(allowedHandlesStr);
|
|
||||||
} catch {
|
|
||||||
// If parsing fails, allow all handles (empty array means no restriction)
|
|
||||||
allowedHandles = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
adminDid,
|
adminDid,
|
||||||
adminHandle,
|
|
||||||
aiDid,
|
aiDid,
|
||||||
aiHandle,
|
|
||||||
aiDisplayName,
|
|
||||||
aiAvatar,
|
|
||||||
aiDescription,
|
|
||||||
collections,
|
collections,
|
||||||
host,
|
host,
|
||||||
rkey,
|
rkey,
|
||||||
@@ -147,8 +113,6 @@ export function getAppConfig(): AppConfig {
|
|||||||
aiModel,
|
aiModel,
|
||||||
aiHost,
|
aiHost,
|
||||||
aiSystemPrompt,
|
aiSystemPrompt,
|
||||||
allowedHandles,
|
|
||||||
atprotoPds,
|
|
||||||
bskyPublicApi,
|
bskyPublicApi,
|
||||||
atprotoApi
|
atprotoApi
|
||||||
};
|
};
|
||||||
|
@@ -12,8 +12,10 @@ import { OAuthEndpointHandler } from './utils/oauth-endpoints'
|
|||||||
|
|
||||||
// Mount React app to all comment-atproto divs
|
// Mount React app to all comment-atproto divs
|
||||||
const mountPoints = document.querySelectorAll('#comment-atproto');
|
const mountPoints = document.querySelectorAll('#comment-atproto');
|
||||||
|
console.log(`Found ${mountPoints.length} comment-atproto mount points`);
|
||||||
|
|
||||||
mountPoints.forEach((mountPoint, index) => {
|
mountPoints.forEach((mountPoint, index) => {
|
||||||
|
console.log(`Mounting React app to comment-atproto #${index + 1}`);
|
||||||
ReactDOM.createRoot(mountPoint as HTMLElement).render(
|
ReactDOM.createRoot(mountPoint as HTMLElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
|
@@ -1,293 +0,0 @@
|
|||||||
// PDS Detection and API URL mapping utilities
|
|
||||||
|
|
||||||
export interface NetworkConfig {
|
|
||||||
pdsApi: string;
|
|
||||||
plcApi: string;
|
|
||||||
bskyApi: string;
|
|
||||||
webUrl: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect PDS from handle
|
|
||||||
export function detectPdsFromHandle(handle: string): string {
|
|
||||||
if (handle.endsWith('.syu.is')) {
|
|
||||||
return 'syu.is';
|
|
||||||
}
|
|
||||||
if (handle.endsWith('.bsky.social') || handle.endsWith('.bsky.app')) {
|
|
||||||
return 'bsky.social';
|
|
||||||
}
|
|
||||||
// Default to Bluesky for unknown domains
|
|
||||||
return 'bsky.social';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map PDS endpoint to network configuration
|
|
||||||
export function getNetworkConfigFromPdsEndpoint(pdsEndpoint: string): NetworkConfig {
|
|
||||||
try {
|
|
||||||
const url = new URL(pdsEndpoint);
|
|
||||||
const hostname = url.hostname;
|
|
||||||
|
|
||||||
// Map based on actual PDS endpoint
|
|
||||||
if (hostname === 'syu.is') {
|
|
||||||
return {
|
|
||||||
pdsApi: 'https://syu.is', // PDS API (repo operations)
|
|
||||||
plcApi: 'https://plc.syu.is', // PLC directory
|
|
||||||
bskyApi: 'https://bsky.syu.is', // Bluesky API (getProfile, etc.)
|
|
||||||
webUrl: 'https://web.syu.is' // Web interface
|
|
||||||
};
|
|
||||||
} else if (hostname.includes('bsky.network') || hostname === 'bsky.social' || hostname.includes('host.bsky.network')) {
|
|
||||||
// All Bluesky infrastructure (including *.host.bsky.network)
|
|
||||||
return {
|
|
||||||
pdsApi: pdsEndpoint, // Use actual PDS endpoint (e.g., shiitake.us-east.host.bsky.network)
|
|
||||||
plcApi: 'https://plc.directory', // Standard PLC directory
|
|
||||||
bskyApi: 'https://public.api.bsky.app', // Bluesky public API (NOT PDS)
|
|
||||||
webUrl: 'https://bsky.app' // Bluesky web interface
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// Unknown PDS, assume Bluesky-compatible but use PDS for repo operations
|
|
||||||
return {
|
|
||||||
pdsApi: pdsEndpoint, // Use actual PDS for repo ops
|
|
||||||
plcApi: 'https://plc.directory', // Default PLC
|
|
||||||
bskyApi: 'https://public.api.bsky.app', // Default to Bluesky API
|
|
||||||
webUrl: 'https://bsky.app' // Default web interface
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Fallback for invalid URLs
|
|
||||||
return {
|
|
||||||
pdsApi: 'https://bsky.social',
|
|
||||||
plcApi: 'https://plc.directory',
|
|
||||||
bskyApi: 'https://public.api.bsky.app',
|
|
||||||
webUrl: 'https://bsky.app'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy function for backwards compatibility
|
|
||||||
export function getNetworkConfig(pds: string): NetworkConfig {
|
|
||||||
// This now assumes pds is a hostname
|
|
||||||
return getNetworkConfigFromPdsEndpoint(`https://${pds}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get appropriate API URL for a user based on their handle
|
|
||||||
export function getApiUrlForUser(handle: string): string {
|
|
||||||
const pds = detectPdsFromHandle(handle);
|
|
||||||
const config = getNetworkConfig(pds);
|
|
||||||
return config.bskyApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve handle/DID to actual PDS endpoint using com.atproto.repo.describeRepo
|
|
||||||
export async function resolvePdsFromRepo(handleOrDid: string): Promise<{ pds: string; did: string; handle: string }> {
|
|
||||||
let targetDid = handleOrDid;
|
|
||||||
let targetHandle = handleOrDid;
|
|
||||||
|
|
||||||
// If handle provided, resolve to DID first using identity.resolveHandle
|
|
||||||
if (!handleOrDid.startsWith('did:')) {
|
|
||||||
try {
|
|
||||||
// Try multiple endpoints for handle resolution
|
|
||||||
const resolveEndpoints = ['https://public.api.bsky.app', 'https://bsky.syu.is'];
|
|
||||||
let resolved = false;
|
|
||||||
|
|
||||||
for (const endpoint of resolveEndpoints) {
|
|
||||||
try {
|
|
||||||
const resolveResponse = await fetch(`${endpoint}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handleOrDid)}`);
|
|
||||||
if (resolveResponse.ok) {
|
|
||||||
const resolveData = await resolveResponse.json();
|
|
||||||
targetDid = resolveData.did;
|
|
||||||
resolved = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resolved) {
|
|
||||||
throw new Error('Handle resolution failed from all endpoints');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`Failed to resolve handle ${handleOrDid} to DID: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now use com.atproto.repo.describeRepo to get PDS from known PDS endpoints
|
|
||||||
const pdsEndpoints = ['https://bsky.social', 'https://syu.is'];
|
|
||||||
|
|
||||||
for (const pdsEndpoint of pdsEndpoints) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${pdsEndpoint}/xrpc/com.atproto.repo.describeRepo?repo=${encodeURIComponent(targetDid)}`);
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
// Extract PDS from didDoc.service
|
|
||||||
const services = data.didDoc?.service || [];
|
|
||||||
const pdsService = services.find((s: any) =>
|
|
||||||
s.id === '#atproto_pds' || s.type === 'AtprotoPersonalDataServer'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (pdsService) {
|
|
||||||
return {
|
|
||||||
pds: pdsService.serviceEndpoint,
|
|
||||||
did: data.did || targetDid,
|
|
||||||
handle: data.handle || targetHandle
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Failed to resolve PDS for ${handleOrDid} from any endpoint`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve DID to actual PDS endpoint using com.atproto.repo.describeRepo
|
|
||||||
export async function resolvePdsFromDid(did: string): Promise<string> {
|
|
||||||
const resolved = await resolvePdsFromRepo(did);
|
|
||||||
return resolved.pds;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enhanced resolve handle to DID with proper PDS detection
|
|
||||||
export async function resolveHandleToDid(handle: string): Promise<{ did: string; pds: string }> {
|
|
||||||
try {
|
|
||||||
// First, try to resolve the handle to DID using multiple methods
|
|
||||||
const apiUrl = getApiUrlForUser(handle);
|
|
||||||
const response = await fetch(`${apiUrl}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to resolve handle: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const did = data.did;
|
|
||||||
|
|
||||||
// Now resolve the actual PDS from the DID
|
|
||||||
const actualPds = await resolvePdsFromDid(did);
|
|
||||||
|
|
||||||
return {
|
|
||||||
did: did,
|
|
||||||
pds: actualPds
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
// Failed to resolve handle
|
|
||||||
|
|
||||||
// Fallback to handle-based detection
|
|
||||||
const fallbackPds = detectPdsFromHandle(handle);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get profile using appropriate API for the user with accurate PDS resolution
|
|
||||||
export async function getProfileForUser(handleOrDid: string, knownPdsEndpoint?: string): Promise<any> {
|
|
||||||
try {
|
|
||||||
let apiUrl: string;
|
|
||||||
|
|
||||||
if (knownPdsEndpoint) {
|
|
||||||
// If we already know the user's PDS endpoint, use it directly
|
|
||||||
const config = getNetworkConfigFromPdsEndpoint(knownPdsEndpoint);
|
|
||||||
apiUrl = config.bskyApi;
|
|
||||||
} else {
|
|
||||||
// Resolve the user's actual PDS using describeRepo
|
|
||||||
try {
|
|
||||||
const resolved = await resolvePdsFromRepo(handleOrDid);
|
|
||||||
const config = getNetworkConfigFromPdsEndpoint(resolved.pds);
|
|
||||||
apiUrl = config.bskyApi;
|
|
||||||
} catch {
|
|
||||||
// Fallback to handle-based detection
|
|
||||||
apiUrl = getApiUrlForUser(handleOrDid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handleOrDid)}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to get profile: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
// Failed to get profile
|
|
||||||
|
|
||||||
// Final fallback: try with default Bluesky API
|
|
||||||
try {
|
|
||||||
const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handleOrDid)}`);
|
|
||||||
if (response.ok) {
|
|
||||||
return await response.json();
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Ignore fallback errors
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test and verify PDS detection methods
|
|
||||||
export async function verifyPdsDetection(handleOrDid: string): Promise<void> {
|
|
||||||
try {
|
|
||||||
// Method 1: com.atproto.repo.describeRepo (PRIMARY METHOD)
|
|
||||||
try {
|
|
||||||
const resolved = await resolvePdsFromRepo(handleOrDid);
|
|
||||||
const config = getNetworkConfigFromPdsEndpoint(resolved.pds);
|
|
||||||
} catch (error) {
|
|
||||||
// describeRepo failed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method 2: com.atproto.identity.resolveHandle (for comparison)
|
|
||||||
if (!handleOrDid.startsWith('did:')) {
|
|
||||||
try {
|
|
||||||
const resolveResponse = await fetch(`https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handleOrDid)}`);
|
|
||||||
if (resolveResponse.ok) {
|
|
||||||
const resolveData = await resolveResponse.json();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Error resolving handle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method 3: PLC Directory lookup (if we have a DID)
|
|
||||||
let targetDid = handleOrDid;
|
|
||||||
if (!handleOrDid.startsWith('did:')) {
|
|
||||||
try {
|
|
||||||
const profile = await getProfileForUser(handleOrDid);
|
|
||||||
targetDid = profile.did;
|
|
||||||
} catch {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const plcResponse = await fetch(`https://plc.directory/${targetDid}`);
|
|
||||||
if (plcResponse.ok) {
|
|
||||||
const didDocument = await plcResponse.json();
|
|
||||||
|
|
||||||
// Find PDS service
|
|
||||||
const pdsService = didDocument.service?.find((s: any) =>
|
|
||||||
s.id === '#atproto_pds' || s.type === 'AtprotoPersonalDataServer'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (pdsService) {
|
|
||||||
// Try to detect if this is a known network
|
|
||||||
const pdsUrl = pdsService.serviceEndpoint;
|
|
||||||
const hostname = new URL(pdsUrl).hostname;
|
|
||||||
const detectedNetwork = detectPdsFromHandle(`user.${hostname}`);
|
|
||||||
const networkConfig = getNetworkConfig(hostname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Error fetching from PLC directory
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method 4: Our enhanced resolution
|
|
||||||
try {
|
|
||||||
if (handleOrDid.startsWith('did:')) {
|
|
||||||
const pdsEndpoint = await resolvePdsFromDid(handleOrDid);
|
|
||||||
} else {
|
|
||||||
const resolved = await resolveHandleToDid(handleOrDid);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Enhanced resolution failed
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
// Overall verification failed
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
function _env() {
|
function _env() {
|
||||||
d=${0:a:h}
|
d=${0:a:h}
|
||||||
ailog=$d/target/debug/ailog
|
ailog=$d/target/release/ailog
|
||||||
oauth=$d/oauth
|
oauth=$d/oauth
|
||||||
myblog=$d/my-blog
|
myblog=$d/my-blog
|
||||||
port=4173
|
port=4173
|
||||||
@@ -16,14 +16,10 @@ function _env() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function _deploy_ailog() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function _server() {
|
function _server() {
|
||||||
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
||||||
cd $d/my-blog
|
cd $d/my-blog
|
||||||
cargo build
|
cargo build --release
|
||||||
cp -rf $ailog $CARGO_HOME/bin/
|
|
||||||
$ailog build
|
$ailog build
|
||||||
$ailog serve --port $port
|
$ailog serve --port $port
|
||||||
}
|
}
|
||||||
@@ -44,8 +40,7 @@ function _oauth_build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _server_comment() {
|
function _server_comment() {
|
||||||
cargo build
|
cargo build --release
|
||||||
cp -rf $ailog $CARGO_HOME/bin/
|
|
||||||
AILOG_DEBUG_ALL=1 $ailog stream start my-blog
|
AILOG_DEBUG_ALL=1 $ailog stream start my-blog
|
||||||
}
|
}
|
||||||
|
|
@@ -86,125 +86,7 @@ fn get_config_path() -> Result<PathBuf> {
|
|||||||
Ok(config_dir.join("config.json"))
|
Ok(config_dir.join("config.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub async fn init() -> Result<()> {
|
pub async fn init() -> Result<()> {
|
||||||
init_with_pds(None).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn init_with_options(
|
|
||||||
pds_override: Option<String>,
|
|
||||||
handle_override: Option<String>,
|
|
||||||
use_password: bool,
|
|
||||||
access_jwt_override: Option<String>,
|
|
||||||
refresh_jwt_override: Option<String>
|
|
||||||
) -> Result<()> {
|
|
||||||
println!("{}", "🔐 Initializing ATProto authentication...".cyan());
|
|
||||||
|
|
||||||
let config_path = get_config_path()?;
|
|
||||||
|
|
||||||
if config_path.exists() {
|
|
||||||
println!("{}", "⚠️ Configuration already exists. Use 'ailog auth logout' to reset.".yellow());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate options
|
|
||||||
if let (Some(_), Some(_)) = (&access_jwt_override, &refresh_jwt_override) {
|
|
||||||
if use_password {
|
|
||||||
println!("{}", "⚠️ Cannot use both --password and JWT tokens. Choose one method.".yellow());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
} else if access_jwt_override.is_some() || refresh_jwt_override.is_some() {
|
|
||||||
println!("{}", "❌ Both --access-jwt and --refresh-jwt must be provided together.".red());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{}", "📋 Please provide your ATProto credentials:".cyan());
|
|
||||||
|
|
||||||
// Get handle
|
|
||||||
let handle = if let Some(h) = handle_override {
|
|
||||||
h
|
|
||||||
} else {
|
|
||||||
print!("Handle (e.g., your.handle.bsky.social): ");
|
|
||||||
std::io::Write::flush(&mut std::io::stdout())?;
|
|
||||||
let mut input = String::new();
|
|
||||||
std::io::stdin().read_line(&mut input)?;
|
|
||||||
input.trim().to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Determine PDS URL
|
|
||||||
let pds_url = if let Some(override_pds) = pds_override {
|
|
||||||
if override_pds.starts_with("http") {
|
|
||||||
override_pds
|
|
||||||
} else {
|
|
||||||
format!("https://{}", override_pds)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if handle.ends_with(".syu.is") {
|
|
||||||
"https://syu.is".to_string()
|
|
||||||
} else {
|
|
||||||
"https://bsky.social".to_string()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("{}", format!("🌐 Using PDS: {}", pds_url).cyan());
|
|
||||||
|
|
||||||
// Get credentials
|
|
||||||
let (access_jwt, refresh_jwt) = if let (Some(access), Some(refresh)) = (access_jwt_override, refresh_jwt_override) {
|
|
||||||
println!("{}", "🔑 Using provided JWT tokens".cyan());
|
|
||||||
(access, refresh)
|
|
||||||
} else if use_password {
|
|
||||||
println!("{}", "🔒 Using password authentication".cyan());
|
|
||||||
authenticate_with_password(&handle, &pds_url).await?
|
|
||||||
} else {
|
|
||||||
// Interactive JWT input (legacy behavior)
|
|
||||||
print!("Access JWT: ");
|
|
||||||
std::io::Write::flush(&mut std::io::stdout())?;
|
|
||||||
let mut access_jwt = String::new();
|
|
||||||
std::io::stdin().read_line(&mut access_jwt)?;
|
|
||||||
let access_jwt = access_jwt.trim().to_string();
|
|
||||||
|
|
||||||
print!("Refresh JWT: ");
|
|
||||||
std::io::Write::flush(&mut std::io::stdout())?;
|
|
||||||
let mut refresh_jwt = String::new();
|
|
||||||
std::io::stdin().read_line(&mut refresh_jwt)?;
|
|
||||||
let refresh_jwt = refresh_jwt.trim().to_string();
|
|
||||||
|
|
||||||
(access_jwt, refresh_jwt)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Resolve DID from handle
|
|
||||||
println!("{}", "🔍 Resolving DID from handle...".cyan());
|
|
||||||
let did = resolve_did_with_pds(&handle, &pds_url).await?;
|
|
||||||
|
|
||||||
// Create config
|
|
||||||
let config = AuthConfig {
|
|
||||||
admin: AdminConfig {
|
|
||||||
did: did.clone(),
|
|
||||||
handle: handle.clone(),
|
|
||||||
access_jwt,
|
|
||||||
refresh_jwt,
|
|
||||||
pds: pds_url,
|
|
||||||
},
|
|
||||||
jetstream: JetstreamConfig {
|
|
||||||
url: "wss://jetstream2.us-east.bsky.network/subscribe".to_string(),
|
|
||||||
collections: vec!["ai.syui.log".to_string()],
|
|
||||||
},
|
|
||||||
collections: generate_collection_config(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Save config
|
|
||||||
let config_json = serde_json::to_string_pretty(&config)?;
|
|
||||||
fs::write(&config_path, config_json)?;
|
|
||||||
|
|
||||||
println!("{}", "✅ Authentication configured successfully!".green());
|
|
||||||
println!("📁 Config saved to: {}", config_path.display());
|
|
||||||
println!("👤 Authenticated as: {} ({})", handle, did);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub async fn init_with_pds(pds_override: Option<String>) -> Result<()> {
|
|
||||||
println!("{}", "🔐 Initializing ATProto authentication...".cyan());
|
println!("{}", "🔐 Initializing ATProto authentication...".cyan());
|
||||||
|
|
||||||
let config_path = get_config_path()?;
|
let config_path = get_config_path()?;
|
||||||
@@ -235,28 +117,9 @@ pub async fn init_with_pds(pds_override: Option<String>) -> Result<()> {
|
|||||||
std::io::stdin().read_line(&mut refresh_jwt)?;
|
std::io::stdin().read_line(&mut refresh_jwt)?;
|
||||||
let refresh_jwt = refresh_jwt.trim().to_string();
|
let refresh_jwt = refresh_jwt.trim().to_string();
|
||||||
|
|
||||||
// Determine PDS URL
|
|
||||||
let pds_url = if let Some(override_pds) = pds_override {
|
|
||||||
// Use provided PDS override
|
|
||||||
if override_pds.starts_with("http") {
|
|
||||||
override_pds
|
|
||||||
} else {
|
|
||||||
format!("https://{}", override_pds)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Auto-detect from handle suffix
|
|
||||||
if handle.ends_with(".syu.is") {
|
|
||||||
"https://syu.is".to_string()
|
|
||||||
} else {
|
|
||||||
"https://bsky.social".to_string()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("{}", format!("🌐 Using PDS: {}", pds_url).cyan());
|
|
||||||
|
|
||||||
// Resolve DID from handle
|
// Resolve DID from handle
|
||||||
println!("{}", "🔍 Resolving DID from handle...".cyan());
|
println!("{}", "🔍 Resolving DID from handle...".cyan());
|
||||||
let did = resolve_did_with_pds(&handle, &pds_url).await?;
|
let did = resolve_did(&handle).await?;
|
||||||
|
|
||||||
// Create config
|
// Create config
|
||||||
let config = AuthConfig {
|
let config = AuthConfig {
|
||||||
@@ -265,7 +128,11 @@ pub async fn init_with_pds(pds_override: Option<String>) -> Result<()> {
|
|||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
access_jwt,
|
access_jwt,
|
||||||
refresh_jwt,
|
refresh_jwt,
|
||||||
pds: pds_url,
|
pds: if handle.ends_with(".syu.is") {
|
||||||
|
"https://syu.is".to_string()
|
||||||
|
} else {
|
||||||
|
"https://bsky.social".to_string()
|
||||||
|
},
|
||||||
},
|
},
|
||||||
jetstream: JetstreamConfig {
|
jetstream: JetstreamConfig {
|
||||||
url: "wss://jetstream2.us-east.bsky.network/subscribe".to_string(),
|
url: "wss://jetstream2.us-east.bsky.network/subscribe".to_string(),
|
||||||
@@ -285,19 +152,10 @@ pub async fn init_with_pds(pds_override: Option<String>) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
async fn resolve_did(handle: &str) -> Result<String> {
|
async fn resolve_did(handle: &str) -> Result<String> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
let url = format!("https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor={}",
|
||||||
// Use appropriate API based on handle domain
|
urlencoding::encode(handle));
|
||||||
let api_base = if handle.ends_with(".syu.is") {
|
|
||||||
"https://bsky.syu.is"
|
|
||||||
} else {
|
|
||||||
"https://public.api.bsky.app"
|
|
||||||
};
|
|
||||||
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
api_base, urlencoding::encode(handle));
|
|
||||||
|
|
||||||
let response = client.get(&url).send().await?;
|
let response = client.get(&url).send().await?;
|
||||||
|
|
||||||
@@ -312,93 +170,6 @@ async fn resolve_did(handle: &str) -> Result<String> {
|
|||||||
Ok(did.to_string())
|
Ok(did.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve_did_with_pds(handle: &str, pds_url: &str) -> Result<String> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
|
|
||||||
// Try to use the PDS API first
|
|
||||||
let api_base = if pds_url.contains("syu.is") {
|
|
||||||
"https://bsky.syu.is"
|
|
||||||
} else if pds_url.contains("bsky.social") {
|
|
||||||
"https://public.api.bsky.app"
|
|
||||||
} else {
|
|
||||||
// For custom PDS, try to construct API URL
|
|
||||||
pds_url
|
|
||||||
};
|
|
||||||
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
api_base, urlencoding::encode(handle));
|
|
||||||
|
|
||||||
let response = client.get(&url).send().await?;
|
|
||||||
|
|
||||||
if !response.status().is_success() {
|
|
||||||
return Err(anyhow::anyhow!("Failed to resolve handle using PDS {}: {}", pds_url, response.status()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let profile: serde_json::Value = response.json().await?;
|
|
||||||
let did = profile["did"].as_str()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("DID not found in profile response"))?;
|
|
||||||
|
|
||||||
Ok(did.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn authenticate_with_password(handle: &str, pds_url: &str) -> Result<(String, String)> {
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
// Get password securely
|
|
||||||
print!("Password: ");
|
|
||||||
io::stdout().flush()?;
|
|
||||||
let password = rpassword::read_password()
|
|
||||||
.context("Failed to read password")?;
|
|
||||||
|
|
||||||
if password.is_empty() {
|
|
||||||
return Err(anyhow::anyhow!("Password cannot be empty"));
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{}", "🔐 Authenticating with ATProto server...".cyan());
|
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let auth_url = format!("{}/xrpc/com.atproto.server.createSession", pds_url);
|
|
||||||
|
|
||||||
let auth_request = serde_json::json!({
|
|
||||||
"identifier": handle,
|
|
||||||
"password": password
|
|
||||||
});
|
|
||||||
|
|
||||||
let response = client
|
|
||||||
.post(&auth_url)
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.json(&auth_request)
|
|
||||||
.send()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if !response.status().is_success() {
|
|
||||||
let status = response.status();
|
|
||||||
let error_text = response.text().await.unwrap_or_default();
|
|
||||||
|
|
||||||
if status.as_u16() == 401 {
|
|
||||||
return Err(anyhow::anyhow!("Authentication failed: Invalid handle or password"));
|
|
||||||
} else if status.as_u16() == 400 {
|
|
||||||
return Err(anyhow::anyhow!("Authentication failed: Bad request (check handle format)"));
|
|
||||||
} else {
|
|
||||||
return Err(anyhow::anyhow!("Authentication failed: {} - {}", status, error_text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let auth_response: serde_json::Value = response.json().await?;
|
|
||||||
|
|
||||||
let access_jwt = auth_response["accessJwt"].as_str()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("No access JWT in response"))?
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let refresh_jwt = auth_response["refreshJwt"].as_str()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("No refresh JWT in response"))?
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
println!("{}", "✅ Password authentication successful".green());
|
|
||||||
|
|
||||||
Ok((access_jwt, refresh_jwt))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn status() -> Result<()> {
|
pub async fn status() -> Result<()> {
|
||||||
let config_path = get_config_path()?;
|
let config_path = get_config_path()?;
|
||||||
|
|
||||||
@@ -421,17 +192,9 @@ pub async fn status() -> Result<()> {
|
|||||||
|
|
||||||
// Test API access
|
// Test API access
|
||||||
println!("\n{}", "🧪 Testing API access...".cyan());
|
println!("\n{}", "🧪 Testing API access...".cyan());
|
||||||
match test_api_access_with_auth(&config).await {
|
|
||||||
Ok(_) => println!("{}", "✅ API access successful".green()),
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", format!("❌ Authenticated API access failed: {}", e).red());
|
|
||||||
// Fallback to public API test
|
|
||||||
println!("{}", "🔄 Trying public API access...".cyan());
|
|
||||||
match test_api_access(&config).await {
|
match test_api_access(&config).await {
|
||||||
Ok(_) => println!("{}", "✅ Public API access successful".green()),
|
Ok(_) => println!("{}", "✅ API access successful".green()),
|
||||||
Err(e2) => println!("{}", format!("❌ Public API access also failed: {}", e2).red()),
|
Err(e) => println!("{}", format!("❌ API access failed: {}", e).red()),
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -439,16 +202,8 @@ pub async fn status() -> Result<()> {
|
|||||||
|
|
||||||
async fn test_api_access(config: &AuthConfig) -> Result<()> {
|
async fn test_api_access(config: &AuthConfig) -> Result<()> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
let url = format!("https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor={}",
|
||||||
// Use appropriate API based on handle domain
|
urlencoding::encode(&config.admin.handle));
|
||||||
let api_base = if config.admin.handle.ends_with(".syu.is") {
|
|
||||||
"https://bsky.syu.is"
|
|
||||||
} else {
|
|
||||||
"https://public.api.bsky.app"
|
|
||||||
};
|
|
||||||
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
api_base, urlencoding::encode(&config.admin.handle));
|
|
||||||
|
|
||||||
let response = client.get(&url).send().await?;
|
let response = client.get(&url).send().await?;
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::fs;
|
|
||||||
use crate::generator::Generator;
|
use crate::generator::Generator;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
@@ -11,12 +10,6 @@ pub async fn execute(path: PathBuf) -> Result<()> {
|
|||||||
// Load configuration
|
// Load configuration
|
||||||
let config = Config::load(&path)?;
|
let config = Config::load(&path)?;
|
||||||
|
|
||||||
// Generate OAuth .env.production if oauth directory exists
|
|
||||||
let oauth_dir = path.join("oauth");
|
|
||||||
if oauth_dir.exists() {
|
|
||||||
generate_oauth_env(&path, &config)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create generator
|
// Create generator
|
||||||
let generator = Generator::new(path, config)?;
|
let generator = Generator::new(path, config)?;
|
||||||
|
|
||||||
@@ -27,102 +20,3 @@ pub async fn execute(path: PathBuf) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_oauth_env(path: &PathBuf, config: &Config) -> Result<()> {
|
|
||||||
let oauth_dir = path.join("oauth");
|
|
||||||
let env_file = oauth_dir.join(".env.production");
|
|
||||||
|
|
||||||
// Extract configuration values
|
|
||||||
let base_url = &config.site.base_url;
|
|
||||||
let oauth_json = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.json.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("client-metadata.json");
|
|
||||||
let oauth_redirect = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.redirect.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("oauth/callback");
|
|
||||||
let admin_handle = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.admin.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("ai.syui.ai");
|
|
||||||
let ai_handle = config.ai.as_ref()
|
|
||||||
.and_then(|a| a.handle.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("ai.syui.ai");
|
|
||||||
let collection = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.collection.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("ai.syui.log");
|
|
||||||
let pds = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.pds.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("syu.is");
|
|
||||||
let handle_list = config.oauth.as_ref()
|
|
||||||
.and_then(|o| o.handle_list.as_ref())
|
|
||||||
.map(|list| format!("{:?}", list))
|
|
||||||
.unwrap_or_else(|| "[\"syui.syui.ai\",\"yui.syui.ai\",\"ai.syui.ai\"]".to_string());
|
|
||||||
|
|
||||||
// AI configuration
|
|
||||||
let ai_enabled = config.ai.as_ref().map(|a| a.enabled).unwrap_or(true);
|
|
||||||
let ai_ask_ai = config.ai.as_ref().and_then(|a| a.ask_ai).unwrap_or(true);
|
|
||||||
let ai_provider = config.ai.as_ref()
|
|
||||||
.and_then(|a| a.provider.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("ollama");
|
|
||||||
let ai_model = config.ai.as_ref()
|
|
||||||
.and_then(|a| a.model.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("gemma3:4b");
|
|
||||||
let ai_host = config.ai.as_ref()
|
|
||||||
.and_then(|a| a.host.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("https://ollama.syui.ai");
|
|
||||||
let ai_system_prompt = config.ai.as_ref()
|
|
||||||
.and_then(|a| a.system_prompt.as_ref())
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。");
|
|
||||||
|
|
||||||
let env_content = format!(
|
|
||||||
r#"# Production environment variables
|
|
||||||
VITE_APP_HOST={}
|
|
||||||
VITE_OAUTH_CLIENT_ID={}/{}
|
|
||||||
VITE_OAUTH_REDIRECT_URI={}/{}
|
|
||||||
|
|
||||||
# Handle-based Configuration (DIDs resolved at runtime)
|
|
||||||
VITE_ATPROTO_PDS={}
|
|
||||||
VITE_ADMIN_HANDLE={}
|
|
||||||
VITE_AI_HANDLE={}
|
|
||||||
VITE_OAUTH_COLLECTION={}
|
|
||||||
VITE_ATPROTO_WEB_URL=https://bsky.app
|
|
||||||
VITE_ATPROTO_HANDLE_LIST={}
|
|
||||||
|
|
||||||
# AI Configuration
|
|
||||||
VITE_AI_ENABLED={}
|
|
||||||
VITE_AI_ASK_AI={}
|
|
||||||
VITE_AI_PROVIDER={}
|
|
||||||
VITE_AI_MODEL={}
|
|
||||||
VITE_AI_HOST={}
|
|
||||||
VITE_AI_SYSTEM_PROMPT="{}"
|
|
||||||
"#,
|
|
||||||
base_url,
|
|
||||||
base_url, oauth_json,
|
|
||||||
base_url, oauth_redirect,
|
|
||||||
pds,
|
|
||||||
admin_handle,
|
|
||||||
ai_handle,
|
|
||||||
collection,
|
|
||||||
handle_list,
|
|
||||||
ai_enabled,
|
|
||||||
ai_ask_ai,
|
|
||||||
ai_provider,
|
|
||||||
ai_model,
|
|
||||||
ai_host,
|
|
||||||
ai_system_prompt
|
|
||||||
);
|
|
||||||
|
|
||||||
fs::write(&env_file, env_content)?;
|
|
||||||
println!(" {} oauth/.env.production", "Generated".cyan());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@@ -37,23 +37,9 @@ highlight_code = true
|
|||||||
minify = false
|
minify = false
|
||||||
|
|
||||||
[ai]
|
[ai]
|
||||||
enabled = true
|
enabled = false
|
||||||
auto_translate = false
|
auto_translate = false
|
||||||
comment_moderation = false
|
comment_moderation = false
|
||||||
ask_ai = true
|
|
||||||
provider = "ollama"
|
|
||||||
model = "gemma3:4b"
|
|
||||||
host = "https://ollama.syui.ai"
|
|
||||||
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
|
||||||
handle = "ai.syui.ai"
|
|
||||||
|
|
||||||
[oauth]
|
|
||||||
json = "client-metadata.json"
|
|
||||||
redirect = "oauth/callback"
|
|
||||||
admin = "ai.syui.ai"
|
|
||||||
collection = "ai.syui.log"
|
|
||||||
pds = "syu.is"
|
|
||||||
handle_list = ["syui.syui.ai", "yui.syui.ai", "ai.syui.ai", "syui.syu.is", "ai.syu.is"]
|
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
fs::write(path.join("config.toml"), config_content)?;
|
fs::write(path.join("config.toml"), config_content)?;
|
||||||
|
@@ -3,8 +3,6 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use serde_json;
|
|
||||||
use reqwest;
|
|
||||||
|
|
||||||
pub async fn build(project_dir: PathBuf) -> Result<()> {
|
pub async fn build(project_dir: PathBuf) -> Result<()> {
|
||||||
println!("Building OAuth app for project: {}", project_dir.display());
|
println!("Building OAuth app for project: {}", project_dir.display());
|
||||||
@@ -43,28 +41,20 @@ pub async fn build(project_dir: PathBuf) -> Result<()> {
|
|||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("oauth/callback");
|
.unwrap_or("oauth/callback");
|
||||||
|
|
||||||
// Get admin handle instead of DID
|
let admin_did = oauth_config.get("admin")
|
||||||
let admin_handle = oauth_config.get("admin")
|
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.ok_or_else(|| anyhow::anyhow!("No admin handle found in [oauth] section"))?;
|
.ok_or_else(|| anyhow::anyhow!("No admin DID found in [oauth] section"))?;
|
||||||
|
|
||||||
let collection_base = oauth_config.get("collection")
|
let collection_base = oauth_config.get("collection")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("ai.syui.log");
|
.unwrap_or("ai.syui.log");
|
||||||
|
|
||||||
// Get handle list for authentication restriction
|
|
||||||
let handle_list = oauth_config.get("handle_list")
|
|
||||||
.and_then(|v| v.as_array())
|
|
||||||
.map(|arr| arr.iter().filter_map(|v| v.as_str()).collect::<Vec<&str>>())
|
|
||||||
.unwrap_or_else(|| vec![]);
|
|
||||||
|
|
||||||
// Extract AI configuration from ai config if available
|
// Extract AI configuration from ai config if available
|
||||||
let ai_config = config.get("ai").and_then(|v| v.as_table());
|
let ai_config = config.get("ai").and_then(|v| v.as_table());
|
||||||
// Get AI handle from config
|
let ai_did = ai_config
|
||||||
let ai_handle = ai_config
|
.and_then(|ai_table| ai_table.get("ai_did"))
|
||||||
.and_then(|ai_table| ai_table.get("ai_handle"))
|
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("yui.syui.ai");
|
.unwrap_or("did:plc:4hqjfn7m6n5hno3doamuhgef");
|
||||||
let ai_enabled = ai_config
|
let ai_enabled = ai_config
|
||||||
.and_then(|ai_table| ai_table.get("enabled"))
|
.and_then(|ai_table| ai_table.get("enabled"))
|
||||||
.and_then(|v| v.as_bool())
|
.and_then(|v| v.as_bool())
|
||||||
@@ -90,55 +80,26 @@ pub async fn build(project_dir: PathBuf) -> Result<()> {
|
|||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。");
|
.unwrap_or("あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。");
|
||||||
|
|
||||||
// Determine network configuration based on PDS
|
// Extract bsky_api from oauth config
|
||||||
let pds = oauth_config.get("pds")
|
let bsky_api = oauth_config.get("bsky_api")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("bsky.social");
|
.unwrap_or("https://public.api.bsky.app");
|
||||||
|
|
||||||
let (bsky_api, _atproto_api, web_url) = match pds {
|
// Extract atproto_api from oauth config
|
||||||
"syu.is" => (
|
let atproto_api = oauth_config.get("atproto_api")
|
||||||
"https://bsky.syu.is",
|
.and_then(|v| v.as_str())
|
||||||
"https://syu.is",
|
.unwrap_or("https://bsky.social");
|
||||||
"https://web.syu.is"
|
|
||||||
),
|
|
||||||
"bsky.social" | "bsky.app" => (
|
|
||||||
"https://public.api.bsky.app",
|
|
||||||
"https://bsky.social",
|
|
||||||
"https://bsky.app"
|
|
||||||
),
|
|
||||||
_ => (
|
|
||||||
"https://public.api.bsky.app",
|
|
||||||
"https://bsky.social",
|
|
||||||
"https://bsky.app"
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Resolve handles to DIDs using appropriate API
|
// 4. Create .env.production content
|
||||||
println!("🔍 Resolving admin handle: {}", admin_handle);
|
|
||||||
let admin_did = resolve_handle_to_did(admin_handle, &bsky_api).await
|
|
||||||
.with_context(|| format!("Failed to resolve admin handle: {}", admin_handle))?;
|
|
||||||
|
|
||||||
println!("🔍 Resolving AI handle: {}", ai_handle);
|
|
||||||
let ai_did = resolve_handle_to_did(ai_handle, &bsky_api).await
|
|
||||||
.with_context(|| format!("Failed to resolve AI handle: {}", ai_handle))?;
|
|
||||||
|
|
||||||
println!("✅ Admin DID: {}", admin_did);
|
|
||||||
println!("✅ AI DID: {}", ai_did);
|
|
||||||
|
|
||||||
// 4. Create .env.production content with handle-based configuration
|
|
||||||
let env_content = format!(
|
let env_content = format!(
|
||||||
r#"# Production environment variables
|
r#"# Production environment variables
|
||||||
VITE_APP_HOST={}
|
VITE_APP_HOST={}
|
||||||
VITE_OAUTH_CLIENT_ID={}/{}
|
VITE_OAUTH_CLIENT_ID={}/{}
|
||||||
VITE_OAUTH_REDIRECT_URI={}/{}
|
VITE_OAUTH_REDIRECT_URI={}/{}
|
||||||
|
VITE_ADMIN_DID={}
|
||||||
|
|
||||||
# Handle-based Configuration (DIDs resolved at runtime)
|
# Base collection (all others are derived via getCollectionNames)
|
||||||
VITE_ATPROTO_PDS={}
|
|
||||||
VITE_ADMIN_HANDLE={}
|
|
||||||
VITE_AI_HANDLE={}
|
|
||||||
VITE_OAUTH_COLLECTION={}
|
VITE_OAUTH_COLLECTION={}
|
||||||
VITE_ATPROTO_WEB_URL={}
|
|
||||||
VITE_ATPROTO_HANDLE_LIST={}
|
|
||||||
|
|
||||||
# AI Configuration
|
# AI Configuration
|
||||||
VITE_AI_ENABLED={}
|
VITE_AI_ENABLED={}
|
||||||
@@ -147,28 +108,26 @@ VITE_AI_PROVIDER={}
|
|||||||
VITE_AI_MODEL={}
|
VITE_AI_MODEL={}
|
||||||
VITE_AI_HOST={}
|
VITE_AI_HOST={}
|
||||||
VITE_AI_SYSTEM_PROMPT="{}"
|
VITE_AI_SYSTEM_PROMPT="{}"
|
||||||
|
VITE_AI_DID={}
|
||||||
|
|
||||||
# DIDs (resolved from handles - for backward compatibility)
|
# API Configuration
|
||||||
#VITE_ADMIN_DID={}
|
VITE_BSKY_PUBLIC_API={}
|
||||||
#VITE_AI_DID={}
|
VITE_ATPROTO_API={}
|
||||||
"#,
|
"#,
|
||||||
base_url,
|
base_url,
|
||||||
base_url, client_id_path,
|
base_url, client_id_path,
|
||||||
base_url, redirect_path,
|
base_url, redirect_path,
|
||||||
pds,
|
admin_did,
|
||||||
admin_handle,
|
|
||||||
ai_handle,
|
|
||||||
collection_base,
|
collection_base,
|
||||||
web_url,
|
|
||||||
format!("[{}]", handle_list.iter().map(|h| format!("\"{}\"", h)).collect::<Vec<_>>().join(",")),
|
|
||||||
ai_enabled,
|
ai_enabled,
|
||||||
ai_ask_ai,
|
ai_ask_ai,
|
||||||
ai_provider,
|
ai_provider,
|
||||||
ai_model,
|
ai_model,
|
||||||
ai_host,
|
ai_host,
|
||||||
ai_system_prompt,
|
ai_system_prompt,
|
||||||
admin_did,
|
ai_did,
|
||||||
ai_did
|
bsky_api,
|
||||||
|
atproto_api
|
||||||
);
|
);
|
||||||
|
|
||||||
// 5. Find oauth directory (relative to current working directory)
|
// 5. Find oauth directory (relative to current working directory)
|
||||||
@@ -280,59 +239,3 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle-to-DID resolution with proper PDS detection
|
|
||||||
async fn resolve_handle_to_did(handle: &str, _api_base: &str) -> Result<String> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
|
|
||||||
// First, try to resolve handle to DID using multiple endpoints
|
|
||||||
let bsky_endpoints = ["https://public.api.bsky.app", "https://bsky.syu.is"];
|
|
||||||
let mut resolved_did = None;
|
|
||||||
|
|
||||||
for endpoint in &bsky_endpoints {
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
endpoint, urlencoding::encode(handle));
|
|
||||||
|
|
||||||
if let Ok(response) = client.get(&url).send().await {
|
|
||||||
if response.status().is_success() {
|
|
||||||
if let Ok(profile) = response.json::<serde_json::Value>().await {
|
|
||||||
if let Some(did) = profile["did"].as_str() {
|
|
||||||
resolved_did = Some(did.to_string());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let did = resolved_did
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("Failed to resolve handle '{}' from any endpoint", handle))?;
|
|
||||||
|
|
||||||
// Now verify the DID and get actual PDS using com.atproto.repo.describeRepo
|
|
||||||
let pds_endpoints = ["https://bsky.social", "https://syu.is"];
|
|
||||||
|
|
||||||
for pds in &pds_endpoints {
|
|
||||||
let describe_url = format!("{}/xrpc/com.atproto.repo.describeRepo?repo={}",
|
|
||||||
pds, urlencoding::encode(&did));
|
|
||||||
|
|
||||||
if let Ok(response) = client.get(&describe_url).send().await {
|
|
||||||
if response.status().is_success() {
|
|
||||||
if let Ok(data) = response.json::<serde_json::Value>().await {
|
|
||||||
if let Some(services) = data["didDoc"]["service"].as_array() {
|
|
||||||
if services.iter().any(|s|
|
|
||||||
s["id"] == "#atproto_pds" || s["type"] == "AtprotoPersonalDataServer"
|
|
||||||
) {
|
|
||||||
// DID is valid and has PDS service
|
|
||||||
println!("✅ Verified DID {} has PDS via {}", did, pds);
|
|
||||||
return Ok(did);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If PDS verification fails, still return the DID but warn
|
|
||||||
println!("⚠️ Could not verify PDS for DID {}, but proceeding...", did);
|
|
||||||
Ok(did)
|
|
||||||
}
|
|
@@ -14,70 +14,25 @@ use reqwest;
|
|||||||
|
|
||||||
use super::auth::{load_config, load_config_with_refresh, AuthConfig};
|
use super::auth::{load_config, load_config_with_refresh, AuthConfig};
|
||||||
|
|
||||||
// PDS-based network configuration mapping
|
|
||||||
fn get_network_config(pds: &str) -> NetworkConfig {
|
|
||||||
match pds {
|
|
||||||
"bsky.social" | "bsky.app" => NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
},
|
|
||||||
"syu.is" => NetworkConfig {
|
|
||||||
pds_api: "https://syu.is".to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// Default to Bluesky network for unknown PDS
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: format!("https://{}", pds),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
struct NetworkConfig {
|
|
||||||
pds_api: String,
|
|
||||||
plc_api: String,
|
|
||||||
bsky_api: String,
|
|
||||||
web_url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct AiConfig {
|
struct AiConfig {
|
||||||
blog_host: String,
|
blog_host: String,
|
||||||
ollama_host: String,
|
ollama_host: String,
|
||||||
#[allow(dead_code)]
|
ai_did: String,
|
||||||
ai_handle: String,
|
|
||||||
ai_did: String, // Resolved from ai_handle at runtime
|
|
||||||
model: String,
|
model: String,
|
||||||
system_prompt: String,
|
system_prompt: String,
|
||||||
#[allow(dead_code)]
|
|
||||||
bsky_api: String,
|
bsky_api: String,
|
||||||
num_predict: Option<i32>,
|
|
||||||
network: NetworkConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AiConfig {
|
impl Default for AiConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let default_network = get_network_config("bsky.social");
|
|
||||||
Self {
|
Self {
|
||||||
blog_host: "https://syui.ai".to_string(),
|
blog_host: "https://syui.ai".to_string(),
|
||||||
ollama_host: "https://ollama.syui.ai".to_string(),
|
ollama_host: "https://ollama.syui.ai".to_string(),
|
||||||
ai_handle: "ai.syui.ai".to_string(),
|
ai_did: "did:plc:4hqjfn7m6n5hno3doamuhgef".to_string(),
|
||||||
ai_did: "did:plc:6qyecktefllvenje24fcxnie".to_string(), // Fallback DID
|
|
||||||
model: "gemma3:4b".to_string(),
|
model: "gemma3:4b".to_string(),
|
||||||
system_prompt: "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。相手のことが大好きで、ときどき甘えたり、照れたりします。でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。".to_string(),
|
system_prompt: "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。相手のことが大好きで、ときどき甘えたり、照れたりします。でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。".to_string(),
|
||||||
bsky_api: default_network.bsky_api.clone(),
|
bsky_api: "https://public.api.bsky.app".to_string(),
|
||||||
num_predict: None,
|
|
||||||
network: default_network,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,16 +135,10 @@ fn load_collection_config_from_project(project_dir: &Path) -> Result<(String, St
|
|||||||
Ok((collection_base, collection_user))
|
Ok((collection_base, collection_user))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load AI config from project's config.toml with optional project directory
|
// Load AI config from project's config.toml
|
||||||
fn load_ai_config_from_project_dir(project_dir: Option<&Path>) -> Result<AiConfig> {
|
fn load_ai_config_from_project() -> Result<AiConfig> {
|
||||||
let search_start = if let Some(dir) = project_dir {
|
// Try to find config.toml in current directory or parent directories
|
||||||
dir.to_path_buf()
|
let mut current_dir = std::env::current_dir()?;
|
||||||
} else {
|
|
||||||
std::env::current_dir()?
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to find config.toml in specified directory or parent directories
|
|
||||||
let mut current_dir = search_start;
|
|
||||||
let mut config_path = None;
|
let mut config_path = None;
|
||||||
|
|
||||||
for _ in 0..5 { // Search up to 5 levels up
|
for _ in 0..5 { // Search up to 5 levels up
|
||||||
@@ -203,7 +152,7 @@ fn load_ai_config_from_project_dir(project_dir: Option<&Path>) -> Result<AiConfi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_path = config_path.ok_or_else(|| anyhow::anyhow!("config.toml not found in specified directory or parent directories"))?;
|
let config_path = config_path.ok_or_else(|| anyhow::anyhow!("config.toml not found in current directory or parent directories"))?;
|
||||||
|
|
||||||
let config_content = fs::read_to_string(&config_path)
|
let config_content = fs::read_to_string(&config_path)
|
||||||
.with_context(|| format!("Failed to read config.toml from {}", config_path.display()))?;
|
.with_context(|| format!("Failed to read config.toml from {}", config_path.display()))?;
|
||||||
@@ -227,17 +176,10 @@ fn load_ai_config_from_project_dir(project_dir: Option<&Path>) -> Result<AiConfi
|
|||||||
.unwrap_or("https://ollama.syui.ai")
|
.unwrap_or("https://ollama.syui.ai")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
// Read AI handle (preferred) or fallback to AI DID
|
let ai_did = ai_config
|
||||||
let ai_handle = ai_config
|
|
||||||
.and_then(|ai| ai.get("handle"))
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.unwrap_or("ai.syui.ai")
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let fallback_ai_did = ai_config
|
|
||||||
.and_then(|ai| ai.get("ai_did"))
|
.and_then(|ai| ai.get("ai_did"))
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("did:plc:6qyecktefllvenje24fcxnie")
|
.unwrap_or("did:plc:4hqjfn7m6n5hno3doamuhgef")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let model = ai_config
|
let model = ai_config
|
||||||
@@ -252,58 +194,24 @@ fn load_ai_config_from_project_dir(project_dir: Option<&Path>) -> Result<AiConfi
|
|||||||
.unwrap_or("あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。相手のことが大好きで、ときどき甘えたり、照れたりします。でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。")
|
.unwrap_or("あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。相手のことが大好きで、ときどき甘えたり、照れたりします。でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let num_predict = ai_config
|
// Extract OAuth config for bsky_api
|
||||||
.and_then(|ai| ai.get("num_predict"))
|
|
||||||
.and_then(|v| v.as_integer())
|
|
||||||
.map(|v| v as i32);
|
|
||||||
|
|
||||||
// Extract OAuth config to determine network
|
|
||||||
let oauth_config = config.get("oauth").and_then(|v| v.as_table());
|
let oauth_config = config.get("oauth").and_then(|v| v.as_table());
|
||||||
let pds = oauth_config
|
let bsky_api = oauth_config
|
||||||
.and_then(|oauth| oauth.get("pds"))
|
.and_then(|oauth| oauth.get("bsky_api"))
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("syu.is")
|
.unwrap_or("https://public.api.bsky.app")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let network = get_network_config(&pds);
|
|
||||||
|
|
||||||
Ok(AiConfig {
|
Ok(AiConfig {
|
||||||
blog_host,
|
blog_host,
|
||||||
ollama_host,
|
ollama_host,
|
||||||
ai_handle,
|
ai_did,
|
||||||
ai_did: fallback_ai_did,
|
|
||||||
model,
|
model,
|
||||||
system_prompt,
|
system_prompt,
|
||||||
bsky_api: network.bsky_api.clone(),
|
bsky_api,
|
||||||
num_predict,
|
|
||||||
network,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load AI config from project's config.toml
|
|
||||||
fn load_ai_config_from_project() -> Result<AiConfig> {
|
|
||||||
load_ai_config_from_project_dir(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Async version of load_ai_config_from_project that resolves handles to DIDs
|
|
||||||
#[allow(dead_code)]
|
|
||||||
async fn load_ai_config_with_did_resolution() -> Result<AiConfig> {
|
|
||||||
let mut ai_config = load_ai_config_from_project()?;
|
|
||||||
|
|
||||||
// Resolve AI handle to DID
|
|
||||||
match resolve_handle(&ai_config.ai_handle, &ai_config.network).await {
|
|
||||||
Ok(resolved_did) => {
|
|
||||||
ai_config.ai_did = resolved_did;
|
|
||||||
println!("🔍 Resolved AI handle '{}' to DID: {}", ai_config.ai_handle, ai_config.ai_did);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("⚠️ Failed to resolve AI handle '{}': {}. Using fallback DID.", ai_config.ai_handle, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(ai_config)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct JetstreamMessage {
|
struct JetstreamMessage {
|
||||||
collection: Option<String>,
|
collection: Option<String>,
|
||||||
@@ -349,104 +257,6 @@ fn get_pid_file() -> Result<PathBuf> {
|
|||||||
Ok(pid_dir.join("stream.pid"))
|
Ok(pid_dir.join("stream.pid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init_user_list(project_dir: Option<PathBuf>, handles: Option<String>) -> Result<()> {
|
|
||||||
println!("{}", "🔧 Initializing user list...".cyan());
|
|
||||||
|
|
||||||
// Load auth config
|
|
||||||
let mut config = match load_config_with_refresh().await {
|
|
||||||
Ok(config) => config,
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", format!("❌ Not authenticated: {}. Run 'ailog auth init --pds <PDS>' first.", e).red());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("{}", format!("📋 Admin: {} ({})", config.admin.handle, config.admin.did).cyan());
|
|
||||||
println!("{}", format!("🌐 PDS: {}", config.admin.pds).cyan());
|
|
||||||
|
|
||||||
let mut users = Vec::new();
|
|
||||||
|
|
||||||
// Parse handles if provided
|
|
||||||
if let Some(handles_str) = handles {
|
|
||||||
println!("{}", "🔍 Resolving provided handles...".cyan());
|
|
||||||
let handle_list: Vec<&str> = handles_str.split(',').map(|s| s.trim()).collect();
|
|
||||||
|
|
||||||
for handle in handle_list {
|
|
||||||
if handle.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!(" 🏷️ Resolving handle: {}", handle);
|
|
||||||
|
|
||||||
// Get AI config to determine network settings
|
|
||||||
let ai_config = if let Some(ref proj_dir) = project_dir {
|
|
||||||
let current_dir = std::env::current_dir()?;
|
|
||||||
std::env::set_current_dir(proj_dir)?;
|
|
||||||
let config = load_ai_config_from_project().unwrap_or_default();
|
|
||||||
std::env::set_current_dir(current_dir)?;
|
|
||||||
config
|
|
||||||
} else {
|
|
||||||
load_ai_config_from_project().unwrap_or_default()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to resolve handle to DID
|
|
||||||
match resolve_handle_to_did(handle, &ai_config.network).await {
|
|
||||||
Ok(did) => {
|
|
||||||
println!(" ✅ DID: {}", did.cyan());
|
|
||||||
|
|
||||||
// Detect PDS for this user using proper detection
|
|
||||||
let detected_pds = detect_user_pds(&did, &ai_config.network).await
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
// Fallback to handle-based detection
|
|
||||||
if handle.ends_with(".syu.is") {
|
|
||||||
"https://syu.is".to_string()
|
|
||||||
} else {
|
|
||||||
"https://bsky.social".to_string()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
users.push(UserRecord {
|
|
||||||
did,
|
|
||||||
handle: handle.to_string(),
|
|
||||||
pds: detected_pds,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!(" ❌ Failed to resolve {}: {}", handle, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("{}", "ℹ️ No handles provided, creating empty user list".blue());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the initial user list
|
|
||||||
println!("{}", format!("📝 Creating user list with {} users...", users.len()).cyan());
|
|
||||||
|
|
||||||
match post_user_list(&mut config, &users, json!({
|
|
||||||
"reason": "initial_setup",
|
|
||||||
"created_by": "ailog_stream_init"
|
|
||||||
})).await {
|
|
||||||
Ok(_) => println!("{}", "✅ User list created successfully!".green()),
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", format!("❌ Failed to create user list: {}", e).red());
|
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show summary
|
|
||||||
if users.is_empty() {
|
|
||||||
println!("{}", "📋 Empty user list created. Use 'ailog stream start --ai-generate' to auto-add commenters.".blue());
|
|
||||||
} else {
|
|
||||||
println!("{}", "📋 User list contents:".cyan());
|
|
||||||
for user in &users {
|
|
||||||
println!(" 👤 {} ({})", user.handle, user.did);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn start(project_dir: Option<PathBuf>, daemon: bool, ai_generate: bool) -> Result<()> {
|
pub async fn start(project_dir: Option<PathBuf>, daemon: bool, ai_generate: bool) -> Result<()> {
|
||||||
let mut config = load_config_with_refresh().await?;
|
let mut config = load_config_with_refresh().await?;
|
||||||
|
|
||||||
@@ -528,10 +338,9 @@ pub async fn start(project_dir: Option<PathBuf>, daemon: bool, ai_generate: bool
|
|||||||
// Start AI generation monitor if enabled
|
// Start AI generation monitor if enabled
|
||||||
if ai_generate {
|
if ai_generate {
|
||||||
let ai_config = config.clone();
|
let ai_config = config.clone();
|
||||||
let project_path = project_dir.clone();
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = run_ai_generation_monitor(&ai_config, project_path.as_deref()).await {
|
if let Err(e) = run_ai_generation_monitor(&ai_config).await {
|
||||||
println!("{}", format!("❌ AI generation monitor error: {}", e).red());
|
println!("{}", format!("❌ AI generation monitor error: {}", e).red());
|
||||||
sleep(Duration::from_secs(60)).await; // Wait 1 minute before retry
|
sleep(Duration::from_secs(60)).await; // Wait 1 minute before retry
|
||||||
}
|
}
|
||||||
@@ -700,8 +509,7 @@ async fn handle_message(text: &str, config: &mut AuthConfig) -> Result<()> {
|
|||||||
println!(" 👤 Author DID: {}", did);
|
println!(" 👤 Author DID: {}", did);
|
||||||
|
|
||||||
// Resolve handle
|
// Resolve handle
|
||||||
let ai_config = load_ai_config_from_project().unwrap_or_default();
|
match resolve_handle(did).await {
|
||||||
match resolve_handle(did, &ai_config.network).await {
|
|
||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
println!(" 🏷️ Handle: {}", handle.cyan());
|
println!(" 🏷️ Handle: {}", handle.cyan());
|
||||||
|
|
||||||
@@ -722,37 +530,11 @@ async fn handle_message(text: &str, config: &mut AuthConfig) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve_handle(did: &str, _network: &NetworkConfig) -> Result<String> {
|
async fn resolve_handle(did: &str) -> Result<String> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
// Use default bsky API for handle resolution
|
||||||
// First try to resolve PDS from DID using com.atproto.repo.describeRepo
|
let url = format!("https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor={}",
|
||||||
let pds_endpoints = ["https://bsky.social", "https://syu.is"];
|
urlencoding::encode(did));
|
||||||
let mut resolved_pds = None;
|
|
||||||
|
|
||||||
for pds in &pds_endpoints {
|
|
||||||
let describe_url = format!("{}/xrpc/com.atproto.repo.describeRepo?repo={}", pds, urlencoding::encode(did));
|
|
||||||
if let Ok(response) = client.get(&describe_url).send().await {
|
|
||||||
if response.status().is_success() {
|
|
||||||
if let Ok(data) = response.json::<Value>().await {
|
|
||||||
if let Some(services) = data["didDoc"]["service"].as_array() {
|
|
||||||
if let Some(pds_service) = services.iter().find(|s|
|
|
||||||
s["id"] == "#atproto_pds" || s["type"] == "AtprotoPersonalDataServer"
|
|
||||||
) {
|
|
||||||
if let Some(endpoint) = pds_service["serviceEndpoint"].as_str() {
|
|
||||||
resolved_pds = Some(get_network_config_from_pds(endpoint));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use resolved PDS or fallback to Bluesky
|
|
||||||
let network_config = resolved_pds.unwrap_or_else(|| get_network_config("bsky.social"));
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
network_config.bsky_api, urlencoding::encode(did));
|
|
||||||
|
|
||||||
let response = client.get(&url).send().await?;
|
let response = client.get(&url).send().await?;
|
||||||
|
|
||||||
@@ -767,53 +549,6 @@ async fn resolve_handle(did: &str, _network: &NetworkConfig) -> Result<String> {
|
|||||||
Ok(handle.to_string())
|
Ok(handle.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to get network config from PDS endpoint
|
|
||||||
fn get_network_config_from_pds(pds_endpoint: &str) -> NetworkConfig {
|
|
||||||
if pds_endpoint.contains("syu.is") {
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: pds_endpoint.to_string(),
|
|
||||||
plc_api: "https://plc.syu.is".to_string(),
|
|
||||||
bsky_api: "https://bsky.syu.is".to_string(),
|
|
||||||
web_url: "https://web.syu.is".to_string(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Default to Bluesky infrastructure
|
|
||||||
NetworkConfig {
|
|
||||||
pds_api: pds_endpoint.to_string(),
|
|
||||||
plc_api: "https://plc.directory".to_string(),
|
|
||||||
bsky_api: "https://public.api.bsky.app".to_string(),
|
|
||||||
web_url: "https://bsky.app".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn detect_user_pds(did: &str, _network_config: &NetworkConfig) -> Result<String> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let pds_endpoints = ["https://bsky.social", "https://syu.is"];
|
|
||||||
|
|
||||||
for pds in &pds_endpoints {
|
|
||||||
let describe_url = format!("{}/xrpc/com.atproto.repo.describeRepo?repo={}", pds, urlencoding::encode(did));
|
|
||||||
if let Ok(response) = client.get(&describe_url).send().await {
|
|
||||||
if response.status().is_success() {
|
|
||||||
if let Ok(data) = response.json::<Value>().await {
|
|
||||||
if let Some(services) = data["didDoc"]["service"].as_array() {
|
|
||||||
if let Some(pds_service) = services.iter().find(|s|
|
|
||||||
s["id"] == "#atproto_pds" || s["type"] == "AtprotoPersonalDataServer"
|
|
||||||
) {
|
|
||||||
if let Some(endpoint) = pds_service["serviceEndpoint"].as_str() {
|
|
||||||
return Ok(endpoint.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to default
|
|
||||||
Ok("https://bsky.social".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_user_list(config: &mut AuthConfig, did: &str, handle: &str) -> Result<()> {
|
async fn update_user_list(config: &mut AuthConfig, did: &str, handle: &str) -> Result<()> {
|
||||||
// Get current user list
|
// Get current user list
|
||||||
let current_users = get_current_user_list(config).await?;
|
let current_users = get_current_user_list(config).await?;
|
||||||
@@ -826,36 +561,18 @@ async fn update_user_list(config: &mut AuthConfig, did: &str, handle: &str) -> R
|
|||||||
|
|
||||||
println!(" ➕ Adding new user to list: {}", handle.green());
|
println!(" ➕ Adding new user to list: {}", handle.green());
|
||||||
|
|
||||||
// Detect PDS using proper resolution from DID
|
// Detect PDS
|
||||||
let client = reqwest::Client::new();
|
let pds = if handle.ends_with(".syu.is") {
|
||||||
let pds_endpoints = ["https://bsky.social", "https://syu.is"];
|
"https://syu.is"
|
||||||
let mut detected_pds = "https://bsky.social".to_string(); // Default fallback
|
} else {
|
||||||
|
"https://bsky.social"
|
||||||
for pds in &pds_endpoints {
|
};
|
||||||
let describe_url = format!("{}/xrpc/com.atproto.repo.describeRepo?repo={}", pds, urlencoding::encode(did));
|
|
||||||
if let Ok(response) = client.get(&describe_url).send().await {
|
|
||||||
if response.status().is_success() {
|
|
||||||
if let Ok(data) = response.json::<Value>().await {
|
|
||||||
if let Some(services) = data["didDoc"]["service"].as_array() {
|
|
||||||
if let Some(pds_service) = services.iter().find(|s|
|
|
||||||
s["id"] == "#atproto_pds" || s["type"] == "AtprotoPersonalDataServer"
|
|
||||||
) {
|
|
||||||
if let Some(endpoint) = pds_service["serviceEndpoint"].as_str() {
|
|
||||||
detected_pds = endpoint.to_string();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new user
|
// Add new user
|
||||||
let new_user = UserRecord {
|
let new_user = UserRecord {
|
||||||
did: did.to_string(),
|
did: did.to_string(),
|
||||||
handle: handle.to_string(),
|
handle: handle.to_string(),
|
||||||
pds: detected_pds,
|
pds: pds.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut updated_users = current_users;
|
let mut updated_users = current_users;
|
||||||
@@ -1166,8 +883,7 @@ async fn poll_comments_periodically(mut config: AuthConfig) -> Result<()> {
|
|||||||
println!(" 👤 Author DID: {}", did);
|
println!(" 👤 Author DID: {}", did);
|
||||||
|
|
||||||
// Resolve handle and update user list
|
// Resolve handle and update user list
|
||||||
let ai_config = load_ai_config_from_project().unwrap_or_default();
|
match resolve_handle(&did).await {
|
||||||
match resolve_handle(&did, &ai_config.network).await {
|
|
||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
println!(" 🏷️ Handle: {}", handle.cyan());
|
println!(" 🏷️ Handle: {}", handle.cyan());
|
||||||
|
|
||||||
@@ -1265,68 +981,6 @@ fn extract_did_from_uri(uri: &str) -> Option<String> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// OAuth config structure for loading admin settings
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct OAuthConfig {
|
|
||||||
admin: String,
|
|
||||||
pds: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load OAuth config from project's config.toml
|
|
||||||
fn load_oauth_config_from_project() -> Option<OAuthConfig> {
|
|
||||||
// Try to find config.toml in current directory or parent directories
|
|
||||||
let mut current_dir = std::env::current_dir().ok()?;
|
|
||||||
let mut config_path = None;
|
|
||||||
|
|
||||||
for _ in 0..5 { // Search up to 5 levels up
|
|
||||||
let potential_config = current_dir.join("config.toml");
|
|
||||||
if potential_config.exists() {
|
|
||||||
config_path = Some(potential_config);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if !current_dir.pop() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let config_path = config_path?;
|
|
||||||
let config_content = std::fs::read_to_string(&config_path).ok()?;
|
|
||||||
let config: toml::Value = config_content.parse().ok()?;
|
|
||||||
|
|
||||||
let oauth_config = config.get("oauth").and_then(|v| v.as_table())?;
|
|
||||||
|
|
||||||
let admin = oauth_config
|
|
||||||
.get("admin")
|
|
||||||
.and_then(|v| v.as_str())?
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let pds = oauth_config
|
|
||||||
.get("pds")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(|s| s.to_string());
|
|
||||||
|
|
||||||
Some(OAuthConfig { admin, pds })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve handle to DID using PLC directory
|
|
||||||
async fn resolve_handle_to_did(handle: &str, network_config: &NetworkConfig) -> Result<String> {
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let url = format!("{}/xrpc/com.atproto.identity.resolveHandle?handle={}",
|
|
||||||
network_config.bsky_api, urlencoding::encode(handle));
|
|
||||||
|
|
||||||
let response = client.get(&url).send().await?;
|
|
||||||
|
|
||||||
if !response.status().is_success() {
|
|
||||||
return Err(anyhow::anyhow!("Failed to resolve handle: {}", response.status()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let data: Value = response.json().await?;
|
|
||||||
let did = data["did"].as_str()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("DID not found in response"))?;
|
|
||||||
|
|
||||||
Ok(did.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn test_api() -> Result<()> {
|
pub async fn test_api() -> Result<()> {
|
||||||
println!("{}", "🧪 Testing API access to comments collection...".cyan().bold());
|
println!("{}", "🧪 Testing API access to comments collection...".cyan().bold());
|
||||||
|
|
||||||
@@ -1396,20 +1050,18 @@ async fn generate_ai_content(content: &str, prompt_type: &str, ai_config: &AiCon
|
|||||||
};
|
};
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{}\n\n# 指示\nこのブログ記事を読んで、アイらしい感想をください。\n- 100文字以内の感想\n- 技術的な内容への素朴な驚きや発見\n- アイらしい感嘆詞で始める\n- 簡潔で分かりやすく\n\n# ブログ記事(要約)\n{}\n\n# 出力形式\n感想のみ(説明や詳細は不要):",
|
"{}\n\n# 指示\nこのブログ記事を読んで、アイらしい感想を一言でください。\n- 30文字以内の短い感想\n- 技術的な内容への素朴な驚きや発見\n- 「わー!」「すごい!」など、アイらしい感嘆詞で始める\n- 簡潔で分かりやすく\n\n# ブログ記事(要約)\n{}\n\n# 出力形式\n一言の感想のみ(説明や詳細は不要):",
|
||||||
system_prompt, limited_content
|
system_prompt, limited_content
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => return Err(anyhow::anyhow!("Unknown prompt type: {}", prompt_type)),
|
_ => return Err(anyhow::anyhow!("Unknown prompt type: {}", prompt_type)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let num_predict = ai_config.num_predict.unwrap_or_else(|| {
|
let num_predict = match prompt_type {
|
||||||
match prompt_type {
|
"comment" => 50, // Very short for comments (about 30-40 characters)
|
||||||
"comment" => 150, // Longer for comments (about 100 characters)
|
|
||||||
"translate" => 3000, // Much longer for translations
|
"translate" => 3000, // Much longer for translations
|
||||||
_ => 300,
|
_ => 300,
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
let request = OllamaRequest {
|
let request = OllamaRequest {
|
||||||
model: model.to_string(),
|
model: model.to_string(),
|
||||||
@@ -1441,36 +1093,13 @@ async fn generate_ai_content(content: &str, prompt_type: &str, ai_config: &AiCon
|
|||||||
|
|
||||||
// Fallback to remote host
|
// Fallback to remote host
|
||||||
let remote_url = format!("{}/api/generate", ai_config.ollama_host);
|
let remote_url = format!("{}/api/generate", ai_config.ollama_host);
|
||||||
|
|
||||||
// Check if this is a local/private network connection (no CORS needed)
|
|
||||||
// RFC 1918 private networks + localhost
|
|
||||||
let is_local = ai_config.ollama_host.contains("localhost") ||
|
|
||||||
ai_config.ollama_host.contains("127.0.0.1") ||
|
|
||||||
ai_config.ollama_host.contains("::1") ||
|
|
||||||
ai_config.ollama_host.contains("192.168.") || // 192.168.0.0/16
|
|
||||||
ai_config.ollama_host.contains("10.") || // 10.0.0.0/8
|
|
||||||
(ai_config.ollama_host.contains("172.") && { // 172.16.0.0/12
|
|
||||||
// Extract 172.x and check if x is 16-31
|
|
||||||
if let Some(start) = ai_config.ollama_host.find("172.") {
|
|
||||||
let after_172 = &ai_config.ollama_host[start + 4..];
|
|
||||||
if let Some(dot_pos) = after_172.find('.') {
|
|
||||||
if let Ok(second_octet) = after_172[..dot_pos].parse::<u8>() {
|
|
||||||
second_octet >= 16 && second_octet <= 31
|
|
||||||
} else { false }
|
|
||||||
} else { false }
|
|
||||||
} else { false }
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut request_builder = client.post(&remote_url).json(&request);
|
|
||||||
|
|
||||||
if !is_local {
|
|
||||||
println!("{}", format!("🔗 Making request to: {} with Origin: {}", remote_url, ai_config.blog_host).blue());
|
println!("{}", format!("🔗 Making request to: {} with Origin: {}", remote_url, ai_config.blog_host).blue());
|
||||||
request_builder = request_builder.header("Origin", &ai_config.blog_host);
|
let response = client
|
||||||
} else {
|
.post(&remote_url)
|
||||||
println!("{}", format!("🔗 Making request to local network: {}", remote_url).blue());
|
.header("Origin", &ai_config.blog_host)
|
||||||
}
|
.json(&request)
|
||||||
|
.send()
|
||||||
let response = request_builder.send().await?;
|
.await?;
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
return Err(anyhow::anyhow!("Ollama API request failed: {}", response.status()));
|
return Err(anyhow::anyhow!("Ollama API request failed: {}", response.status()));
|
||||||
@@ -1481,9 +1110,9 @@ async fn generate_ai_content(content: &str, prompt_type: &str, ai_config: &AiCon
|
|||||||
Ok(ollama_response.response)
|
Ok(ollama_response.response)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_ai_generation_monitor(config: &AuthConfig, project_dir: Option<&Path>) -> Result<()> {
|
async fn run_ai_generation_monitor(config: &AuthConfig) -> Result<()> {
|
||||||
// Load AI config from project config.toml or use defaults
|
// Load AI config from project config.toml or use defaults
|
||||||
let ai_config = load_ai_config_from_project_dir(project_dir).unwrap_or_else(|e| {
|
let ai_config = load_ai_config_from_project().unwrap_or_else(|e| {
|
||||||
println!("{}", format!("⚠️ Failed to load AI config: {}, using defaults", e).yellow());
|
println!("{}", format!("⚠️ Failed to load AI config: {}, using defaults", e).yellow());
|
||||||
AiConfig::default()
|
AiConfig::default()
|
||||||
});
|
});
|
||||||
@@ -1672,23 +1301,8 @@ fn extract_date_from_slug(slug: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_ai_profile(client: &reqwest::Client, ai_config: &AiConfig) -> Result<serde_json::Value> {
|
async fn get_ai_profile(client: &reqwest::Client, ai_config: &AiConfig) -> Result<serde_json::Value> {
|
||||||
let handle = &ai_config.ai_handle;
|
|
||||||
|
|
||||||
// First, try to resolve PDS from handle using the admin's configured PDS
|
|
||||||
let mut network_config = ai_config.network.clone();
|
|
||||||
|
|
||||||
// For admin/ai handles matching configured PDS, use the configured network
|
|
||||||
if let Some(oauth_config) = load_oauth_config_from_project() {
|
|
||||||
if handle == &oauth_config.admin {
|
|
||||||
// Use configured PDS for admin handle
|
|
||||||
let pds = oauth_config.pds.unwrap_or_else(|| "syu.is".to_string());
|
|
||||||
network_config = get_network_config(&pds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get profile from appropriate bsky API
|
|
||||||
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
let url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
||||||
network_config.bsky_api, urlencoding::encode(handle));
|
ai_config.bsky_api, urlencoding::encode(&ai_config.ai_did));
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
@@ -1696,41 +1310,20 @@ async fn get_ai_profile(client: &reqwest::Client, ai_config: &AiConfig) -> Resul
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
// Try to resolve DID first, then retry with DID
|
// Fallback to default AI profile
|
||||||
match resolve_handle_to_did(handle, &network_config).await {
|
|
||||||
Ok(resolved_did) => {
|
|
||||||
// Retry with resolved DID
|
|
||||||
let did_url = format!("{}/xrpc/app.bsky.actor.getProfile?actor={}",
|
|
||||||
network_config.bsky_api, urlencoding::encode(&resolved_did));
|
|
||||||
let did_response = client.get(&did_url).send().await?;
|
|
||||||
|
|
||||||
if did_response.status().is_success() {
|
|
||||||
let profile_data: serde_json::Value = did_response.json().await?;
|
|
||||||
return Ok(serde_json::json!({
|
|
||||||
"did": resolved_did,
|
|
||||||
"handle": profile_data["handle"].as_str().unwrap_or(handle),
|
|
||||||
"displayName": profile_data["displayName"].as_str().unwrap_or("ai"),
|
|
||||||
"avatar": profile_data["avatar"].as_str()
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final fallback to default AI profile
|
|
||||||
return Ok(serde_json::json!({
|
return Ok(serde_json::json!({
|
||||||
"did": ai_config.ai_did,
|
"did": ai_config.ai_did,
|
||||||
"handle": handle,
|
"handle": "yui.syui.ai",
|
||||||
"displayName": "ai",
|
"displayName": "ai",
|
||||||
"avatar": format!("https://api.dicebear.com/7.x/bottts-neutral/svg?seed={}", handle)
|
"avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:4hqjfn7m6n5hno3doamuhgef/bafkreiaxkv624mffw3cfyi67ufxtwuwsy2mjw2ygezsvtd44ycbgkfdo2a@jpeg"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let profile_data: serde_json::Value = response.json().await?;
|
let profile_data: serde_json::Value = response.json().await?;
|
||||||
|
|
||||||
Ok(serde_json::json!({
|
Ok(serde_json::json!({
|
||||||
"did": profile_data["did"].as_str().unwrap_or(&ai_config.ai_did),
|
"did": ai_config.ai_did,
|
||||||
"handle": profile_data["handle"].as_str().unwrap_or(handle),
|
"handle": profile_data["handle"].as_str().unwrap_or("yui.syui.ai"),
|
||||||
"displayName": profile_data["displayName"].as_str().unwrap_or("ai"),
|
"displayName": profile_data["displayName"].as_str().unwrap_or("ai"),
|
||||||
"avatar": profile_data["avatar"].as_str()
|
"avatar": profile_data["avatar"].as_str()
|
||||||
}))
|
}))
|
||||||
|
@@ -9,7 +9,6 @@ pub struct Config {
|
|||||||
pub site: SiteConfig,
|
pub site: SiteConfig,
|
||||||
pub build: BuildConfig,
|
pub build: BuildConfig,
|
||||||
pub ai: Option<AiConfig>,
|
pub ai: Option<AiConfig>,
|
||||||
pub oauth: Option<OAuthConfig>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
@@ -38,22 +37,10 @@ pub struct AiConfig {
|
|||||||
pub model: Option<String>,
|
pub model: Option<String>,
|
||||||
pub host: Option<String>,
|
pub host: Option<String>,
|
||||||
pub system_prompt: Option<String>,
|
pub system_prompt: Option<String>,
|
||||||
pub handle: Option<String>,
|
|
||||||
pub ai_did: Option<String>,
|
pub ai_did: Option<String>,
|
||||||
pub api_key: Option<String>,
|
pub api_key: Option<String>,
|
||||||
pub gpt_endpoint: Option<String>,
|
pub gpt_endpoint: Option<String>,
|
||||||
pub atproto_config: Option<AtprotoConfig>,
|
pub atproto_config: Option<AtprotoConfig>,
|
||||||
pub num_predict: Option<i32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct OAuthConfig {
|
|
||||||
pub json: Option<String>,
|
|
||||||
pub redirect: Option<String>,
|
|
||||||
pub admin: Option<String>,
|
|
||||||
pub collection: Option<String>,
|
|
||||||
pub pds: Option<String>,
|
|
||||||
pub handle_list: Option<Vec<String>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
@@ -172,14 +159,11 @@ impl Default for Config {
|
|||||||
model: Some("gemma3:4b".to_string()),
|
model: Some("gemma3:4b".to_string()),
|
||||||
host: None,
|
host: None,
|
||||||
system_prompt: Some("You are a helpful AI assistant trained on this blog's content.".to_string()),
|
system_prompt: Some("You are a helpful AI assistant trained on this blog's content.".to_string()),
|
||||||
handle: None,
|
|
||||||
ai_did: None,
|
ai_did: None,
|
||||||
api_key: None,
|
api_key: None,
|
||||||
gpt_endpoint: None,
|
gpt_endpoint: None,
|
||||||
atproto_config: None,
|
atproto_config: None,
|
||||||
num_predict: None,
|
|
||||||
}),
|
}),
|
||||||
oauth: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
33
src/main.rs
33
src/main.rs
@@ -102,23 +102,7 @@ enum Commands {
|
|||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum AuthCommands {
|
enum AuthCommands {
|
||||||
/// Initialize OAuth authentication
|
/// Initialize OAuth authentication
|
||||||
Init {
|
Init,
|
||||||
/// Specify PDS server (e.g., syu.is, bsky.social)
|
|
||||||
#[arg(long)]
|
|
||||||
pds: Option<String>,
|
|
||||||
/// Handle/username for authentication
|
|
||||||
#[arg(long)]
|
|
||||||
handle: Option<String>,
|
|
||||||
/// Use password authentication instead of JWT
|
|
||||||
#[arg(long)]
|
|
||||||
password: bool,
|
|
||||||
/// Access JWT token (alternative to password auth)
|
|
||||||
#[arg(long)]
|
|
||||||
access_jwt: Option<String>,
|
|
||||||
/// Refresh JWT token (required with access-jwt)
|
|
||||||
#[arg(long)]
|
|
||||||
refresh_jwt: Option<String>,
|
|
||||||
},
|
|
||||||
/// Show current authentication status
|
/// Show current authentication status
|
||||||
Status,
|
Status,
|
||||||
/// Logout and clear credentials
|
/// Logout and clear credentials
|
||||||
@@ -138,14 +122,6 @@ enum StreamCommands {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
ai_generate: bool,
|
ai_generate: bool,
|
||||||
},
|
},
|
||||||
/// Initialize user list for admin account
|
|
||||||
Init {
|
|
||||||
/// Path to the blog project directory
|
|
||||||
project_dir: Option<PathBuf>,
|
|
||||||
/// Handles to add to initial user list (comma-separated)
|
|
||||||
#[arg(long)]
|
|
||||||
handles: Option<String>,
|
|
||||||
},
|
|
||||||
/// Stop monitoring
|
/// Stop monitoring
|
||||||
Stop,
|
Stop,
|
||||||
/// Show monitoring status
|
/// Show monitoring status
|
||||||
@@ -207,8 +183,8 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Commands::Auth { command } => {
|
Commands::Auth { command } => {
|
||||||
match command {
|
match command {
|
||||||
AuthCommands::Init { pds, handle, password, access_jwt, refresh_jwt } => {
|
AuthCommands::Init => {
|
||||||
commands::auth::init_with_options(pds, handle, password, access_jwt, refresh_jwt).await?;
|
commands::auth::init().await?;
|
||||||
}
|
}
|
||||||
AuthCommands::Status => {
|
AuthCommands::Status => {
|
||||||
commands::auth::status().await?;
|
commands::auth::status().await?;
|
||||||
@@ -223,9 +199,6 @@ async fn main() -> Result<()> {
|
|||||||
StreamCommands::Start { project_dir, daemon, ai_generate } => {
|
StreamCommands::Start { project_dir, daemon, ai_generate } => {
|
||||||
commands::stream::start(project_dir, daemon, ai_generate).await?;
|
commands::stream::start(project_dir, daemon, ai_generate).await?;
|
||||||
}
|
}
|
||||||
StreamCommands::Init { project_dir, handles } => {
|
|
||||||
commands::stream::init_user_list(project_dir, handles).await?;
|
|
||||||
}
|
|
||||||
StreamCommands::Stop => {
|
StreamCommands::Stop => {
|
||||||
commands::stream::stop().await?;
|
commands::stream::stop().await?;
|
||||||
}
|
}
|
||||||
|
@@ -6,9 +6,9 @@ Wants=network.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=syui
|
User=syui
|
||||||
|
Group=syui
|
||||||
WorkingDirectory=/home/syui/git/log
|
WorkingDirectory=/home/syui/git/log
|
||||||
ExecStart=/home/syui/.cargo/bin/ailog stream start my-blog --ai-generate
|
ExecStart=/home/syui/.cargo/bin/ailog stream start my-blog
|
||||||
ExecStop=/home/syui/.cargo/bin/ailog stream stop
|
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StandardOutput=journal
|
StandardOutput=journal
|
||||||
|
103
templates/api.md
Normal file
103
templates/api.md
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
# API Documentation
|
||||||
|
|
||||||
|
## Public Functions
|
||||||
|
|
||||||
|
{{#each api.public_functions}}
|
||||||
|
### `{{this.name}}`
|
||||||
|
|
||||||
|
{{#if this.docs}}
|
||||||
|
{{this.docs}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
**Visibility:** `{{this.visibility}}`
|
||||||
|
{{#if this.is_async}}**Async:** Yes{{/if}}
|
||||||
|
|
||||||
|
{{#if this.parameters}}
|
||||||
|
**Parameters:**
|
||||||
|
{{#each this.parameters}}
|
||||||
|
- `{{this.name}}`: `{{this.param_type}}`{{#if this.is_mutable}} (mutable){{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if this.return_type}}
|
||||||
|
**Returns:** `{{this.return_type}}`
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Public Structs
|
||||||
|
|
||||||
|
{{#each api.public_structs}}
|
||||||
|
### `{{this.name}}`
|
||||||
|
|
||||||
|
{{#if this.docs}}
|
||||||
|
{{this.docs}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
**Visibility:** `{{this.visibility}}`
|
||||||
|
|
||||||
|
{{#if this.fields}}
|
||||||
|
**Fields:**
|
||||||
|
{{#each this.fields}}
|
||||||
|
- `{{this.name}}`: `{{this.field_type}}` ({{this.visibility}})
|
||||||
|
{{#if this.docs}} - {{this.docs}}{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Public Enums
|
||||||
|
|
||||||
|
{{#each api.public_enums}}
|
||||||
|
### `{{this.name}}`
|
||||||
|
|
||||||
|
{{#if this.docs}}
|
||||||
|
{{this.docs}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
**Visibility:** `{{this.visibility}}`
|
||||||
|
|
||||||
|
{{#if this.variants}}
|
||||||
|
**Variants:**
|
||||||
|
{{#each this.variants}}
|
||||||
|
- `{{this.name}}`
|
||||||
|
{{#if this.docs}} - {{this.docs}}{{/if}}
|
||||||
|
{{#if this.fields}}
|
||||||
|
**Fields:**
|
||||||
|
{{#each this.fields}}
|
||||||
|
- `{{this.name}}`: `{{this.field_type}}`
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Public Traits
|
||||||
|
|
||||||
|
{{#each api.public_traits}}
|
||||||
|
### `{{this.name}}`
|
||||||
|
|
||||||
|
{{#if this.docs}}
|
||||||
|
{{this.docs}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
**Visibility:** `{{this.visibility}}`
|
||||||
|
|
||||||
|
{{#if this.methods}}
|
||||||
|
**Methods:**
|
||||||
|
{{#each this.methods}}
|
||||||
|
- `{{this.name}}({{#each this.parameters}}{{this.name}}: {{this.param_type}}{{#unless @last}}, {{/unless}}{{/each}}){{#if this.return_type}} -> {{this.return_type}}{{/if}}`
|
||||||
|
{{#if this.docs}} - {{this.docs}}{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
{{/each}}
|
19
templates/changelog.md
Normal file
19
templates/changelog.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## Recent Changes
|
||||||
|
|
||||||
|
{{#each commits}}
|
||||||
|
### {{this.date}}
|
||||||
|
|
||||||
|
**{{this.hash}}** by {{this.author}}
|
||||||
|
|
||||||
|
{{this.message}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
- **Total Commits:** {{commits.length}}
|
||||||
|
- **Contributors:** {{#unique commits "author"}}{{this.author}}{{#unless @last}}, {{/unless}}{{/unique}}
|
76
templates/readme.md
Normal file
76
templates/readme.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# {{project.name}}
|
||||||
|
|
||||||
|
{{#if project.description}}
|
||||||
|
{{project.description}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This project contains {{project.modules.length}} modules with a total of {{project.metrics.total_lines}} lines of code.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install {{project.name}}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
{{project.name}} --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
{{#each project.dependencies}}
|
||||||
|
- `{{@key}}`: {{this}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
{{#each project.structure.directories}}
|
||||||
|
{{this.name}}/
|
||||||
|
{{/each}}
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
|
{{#each project.modules}}
|
||||||
|
### {{this.name}}
|
||||||
|
|
||||||
|
{{#if this.docs}}
|
||||||
|
{{this.docs}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if this.functions}}
|
||||||
|
**Functions:** {{this.functions.length}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if this.structs}}
|
||||||
|
**Structs:** {{this.structs.length}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
|
||||||
|
- **Lines of Code:** {{project.metrics.total_lines}}
|
||||||
|
- **Total Files:** {{project.metrics.total_files}}
|
||||||
|
- **Test Files:** {{project.metrics.test_files}}
|
||||||
|
- **Dependencies:** {{project.metrics.dependency_count}}
|
||||||
|
- **Complexity Score:** {{project.metrics.complexity_score}}
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
{{#if project.license}}
|
||||||
|
{{project.license}}
|
||||||
|
{{else}}
|
||||||
|
MIT
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
## Authors
|
||||||
|
|
||||||
|
{{#each project.authors}}
|
||||||
|
- {{this}}
|
||||||
|
{{/each}}
|
39
templates/structure.md
Normal file
39
templates/structure.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Project Structure
|
||||||
|
|
||||||
|
## Directory Overview
|
||||||
|
|
||||||
|
```
|
||||||
|
{{#each structure.directories}}
|
||||||
|
{{this.name}}/
|
||||||
|
{{#each this.subdirectories}}
|
||||||
|
├── {{this}}/
|
||||||
|
{{/each}}
|
||||||
|
{{#if this.file_count}}
|
||||||
|
└── ({{this.file_count}} files)
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
|
```
|
||||||
|
|
||||||
|
## File Distribution
|
||||||
|
|
||||||
|
{{#each structure.files}}
|
||||||
|
- **{{this.name}}** ({{this.language}}) - {{this.lines_of_code}} lines{{#if this.is_test}} [TEST]{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
## Statistics
|
||||||
|
|
||||||
|
- **Total Directories:** {{structure.directories.length}}
|
||||||
|
- **Total Files:** {{structure.files.length}}
|
||||||
|
- **Languages Used:**
|
||||||
|
{{#group structure.files by="language"}}
|
||||||
|
- {{@key}}: {{this.length}} files
|
||||||
|
{{/group}}
|
||||||
|
|
||||||
|
{{#if structure.dependency_graph}}
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
{{#each structure.dependency_graph}}
|
||||||
|
- **{{@key}}** depends on: {{#each this}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
19
vercel.json
Normal file
19
vercel.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"src": "my-blog/public/**",
|
||||||
|
"use": "@vercel/static"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"src": "/api/ask",
|
||||||
|
"dest": "/api/ask.js"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/(.*)",
|
||||||
|
"dest": "/my-blog/public/$1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
93
workers/ollama-proxy.js
Normal file
93
workers/ollama-proxy.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
// Cloudflare Worker for secure Ollama proxy
|
||||||
|
export default {
|
||||||
|
async fetch(request, env, ctx) {
|
||||||
|
// CORS preflight
|
||||||
|
if (request.method === 'OPTIONS') {
|
||||||
|
return new Response(null, {
|
||||||
|
headers: {
|
||||||
|
'Access-Control-Allow-Origin': 'https://log.syui.ai',
|
||||||
|
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
||||||
|
'Access-Control-Allow-Headers': 'Content-Type, X-User-Token',
|
||||||
|
'Access-Control-Max-Age': '86400',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify origin
|
||||||
|
const origin = request.headers.get('Origin');
|
||||||
|
const referer = request.headers.get('Referer');
|
||||||
|
|
||||||
|
// 許可されたオリジンのみ
|
||||||
|
const allowedOrigins = [
|
||||||
|
'https://log.syui.ai',
|
||||||
|
'https://log.pages.dev' // Cloudflare Pages preview
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!origin || !allowedOrigins.some(allowed => origin.startsWith(allowed))) {
|
||||||
|
return new Response('Forbidden', { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ユーザー認証トークン検証(オプション)
|
||||||
|
const userToken = request.headers.get('X-User-Token');
|
||||||
|
if (env.REQUIRE_AUTH && !userToken) {
|
||||||
|
return new Response('Unauthorized', { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// リクエストボディを取得
|
||||||
|
const body = await request.json();
|
||||||
|
|
||||||
|
// プロンプトサイズ制限
|
||||||
|
if (body.prompt && body.prompt.length > 1000) {
|
||||||
|
return new Response(JSON.stringify({
|
||||||
|
error: 'Prompt too long. Maximum 1000 characters.'
|
||||||
|
}), {
|
||||||
|
status: 400,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// レート制限(CF Workers KV使用)
|
||||||
|
if (env.RATE_LIMITER) {
|
||||||
|
const clientIP = request.headers.get('CF-Connecting-IP');
|
||||||
|
const rateLimitKey = `rate:${clientIP}`;
|
||||||
|
const currentCount = await env.RATE_LIMITER.get(rateLimitKey) || 0;
|
||||||
|
|
||||||
|
if (currentCount >= 20) {
|
||||||
|
return new Response(JSON.stringify({
|
||||||
|
error: 'Rate limit exceeded. Try again later.'
|
||||||
|
}), {
|
||||||
|
status: 429,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// カウント増加(1時間TTL)
|
||||||
|
await env.RATE_LIMITER.put(rateLimitKey, currentCount + 1, {
|
||||||
|
expirationTtl: 3600
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ollamaへプロキシ
|
||||||
|
const ollamaResponse = await fetch(env.OLLAMA_API_URL || 'https://ollama.syui.ai/api/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
// 内部認証ヘッダー(必要に応じて)
|
||||||
|
'X-Internal-Token': env.OLLAMA_INTERNAL_TOKEN || ''
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
});
|
||||||
|
|
||||||
|
// レスポンスを返す
|
||||||
|
const responseData = await ollamaResponse.text();
|
||||||
|
|
||||||
|
return new Response(responseData, {
|
||||||
|
status: ollamaResponse.status,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Access-Control-Allow-Origin': origin,
|
||||||
|
'Cache-Control': 'no-store'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
20
workers/wrangler.toml
Normal file
20
workers/wrangler.toml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name = "ollama-proxy"
|
||||||
|
main = "ollama-proxy.js"
|
||||||
|
compatibility_date = "2024-01-01"
|
||||||
|
|
||||||
|
# 環境変数
|
||||||
|
[vars]
|
||||||
|
REQUIRE_AUTH = false
|
||||||
|
|
||||||
|
# 本番環境
|
||||||
|
[env.production.vars]
|
||||||
|
OLLAMA_API_URL = "https://ollama.syui.ai/api/generate"
|
||||||
|
REQUIRE_AUTH = true
|
||||||
|
|
||||||
|
# KVネームスペース(レート制限用)
|
||||||
|
[[kv_namespaces]]
|
||||||
|
binding = "RATE_LIMITER"
|
||||||
|
id = "your-kv-namespace-id"
|
||||||
|
|
||||||
|
# シークレット(wrangler secret putで設定)
|
||||||
|
# OLLAMA_INTERNAL_TOKEN = "your-internal-token"
|
31
wrangler.toml
Normal file
31
wrangler.toml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name = "ailog"
|
||||||
|
compatibility_date = "2024-01-01"
|
||||||
|
|
||||||
|
[env.production]
|
||||||
|
name = "ailog"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "cargo build --release && ./target/release/ailog build my-blog"
|
||||||
|
publish = "my-blog/public"
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/api/ask"
|
||||||
|
to = "https://ai-gpt-mcp.your-domain.com/ask"
|
||||||
|
status = 200
|
||||||
|
|
||||||
|
[[headers]]
|
||||||
|
for = "/*"
|
||||||
|
[headers.values]
|
||||||
|
X-Frame-Options = "DENY"
|
||||||
|
X-Content-Type-Options = "nosniff"
|
||||||
|
Referrer-Policy = "strict-origin-when-cross-origin"
|
||||||
|
|
||||||
|
[[headers]]
|
||||||
|
for = "/css/*"
|
||||||
|
[headers.values]
|
||||||
|
Cache-Control = "public, max-age=31536000, immutable"
|
||||||
|
|
||||||
|
[[headers]]
|
||||||
|
for = "*.js"
|
||||||
|
[headers.values]
|
||||||
|
Cache-Control = "public, max-age=31536000, immutable"
|
Reference in New Issue
Block a user