fix config
This commit is contained in:
@@ -2,9 +2,15 @@
|
||||
"title": "syui.ai",
|
||||
"did": "did:plc:vzsvtbtbnwn22xjqhcu3vd6y",
|
||||
"handle": "syui.syui.ai",
|
||||
"bot": {
|
||||
"did": "did:plc:6qyecktefllvenje24fcxnie",
|
||||
"handle": "ai.syui.ai"
|
||||
},
|
||||
"collection": "ai.syui.log.post",
|
||||
"chatCollection": "ai.syui.log.chat",
|
||||
"network": "syu.is",
|
||||
"color": "#EF454A",
|
||||
"siteUrl": "https://syui.ai",
|
||||
"repoUrl": "https://git.syui.ai/ai/log",
|
||||
"oauth": true
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
"bsky.social": {
|
||||
"plc": "https://plc.directory",
|
||||
"bsky": "https://public.api.bsky.app",
|
||||
"web": "https://bsky.app"
|
||||
"web": "https://bsky.app",
|
||||
"handleDomains": ["bsky.social"]
|
||||
},
|
||||
"syu.is": {
|
||||
"plc": "https://plc.syu.is",
|
||||
"bsky": "https://bsky.syu.is",
|
||||
"web": "https://syu.is"
|
||||
"web": "https://syu.is",
|
||||
"handleDomains": ["syu.is", "syui.ai"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,14 +223,16 @@ fn handle_chat_save(params: ChatSaveParams) -> Result<String> {
|
||||
});
|
||||
|
||||
// Get user DID from token.json
|
||||
let user_did = token::load_session()
|
||||
.map(|s| s.did)
|
||||
.unwrap_or_else(|_| "did:plc:unknown".to_string());
|
||||
let user_did = match token::load_session() {
|
||||
Ok(s) => s.did,
|
||||
Err(_) => return Err(anyhow::anyhow!("User not logged in. Run: ailog login <handle> -p <password>")),
|
||||
};
|
||||
|
||||
// Get bot DID from bot.json
|
||||
let bot_did = token::load_bot_session()
|
||||
.map(|s| s.did)
|
||||
.unwrap_or_else(|_| "did:plc:6qyecktefllvenje24fcxnie".to_string());
|
||||
let bot_did = match token::load_bot_session() {
|
||||
Ok(s) => s.did,
|
||||
Err(_) => return Err(anyhow::anyhow!("Bot not logged in. Run: ailog login <handle> -p <password> --bot")),
|
||||
};
|
||||
|
||||
// Reset session if new_thread requested
|
||||
if params.new_thread {
|
||||
@@ -278,9 +280,10 @@ fn handle_chat_list() -> Result<String> {
|
||||
.to_string()
|
||||
});
|
||||
|
||||
let user_did = token::load_session()
|
||||
.map(|s| s.did)
|
||||
.unwrap_or_else(|_| "did:plc:unknown".to_string());
|
||||
let user_did = match token::load_session() {
|
||||
Ok(s) => s.did,
|
||||
Err(_) => return Err(anyhow::anyhow!("User not logged in. Run: ailog login <handle> -p <password>")),
|
||||
};
|
||||
|
||||
let collection_dir = std::path::Path::new(&output_dir)
|
||||
.join(&user_did)
|
||||
|
||||
@@ -171,10 +171,11 @@ export function renderChatThread(
|
||||
botHandle: string,
|
||||
userProfile?: Profile | null,
|
||||
botProfile?: Profile | null,
|
||||
pds?: string
|
||||
pds?: string,
|
||||
chatCollection: string = 'ai.syui.log.chat'
|
||||
): string {
|
||||
// Find root message
|
||||
const rootUri = `at://${userDid}/ai.syui.log.chat/${rootRkey}`
|
||||
const rootUri = `at://${userDid}/${chatCollection}/${rootRkey}`
|
||||
const rootMsg = messages.find(m => m.uri === rootUri)
|
||||
|
||||
if (!rootMsg) {
|
||||
@@ -222,7 +223,7 @@ export function renderChatThread(
|
||||
|
||||
const displayContent = getTranslatedContent(msg)
|
||||
const content = renderMarkdown(displayContent)
|
||||
const recordLink = `/@${author.handle}/at/collection/ai.syui.log.chat/${rkey}`
|
||||
const recordLink = `/@${author.handle}/at/collection/${chatCollection}/${rkey}`
|
||||
|
||||
return `
|
||||
<article class="chat-message">
|
||||
@@ -268,8 +269,9 @@ export function renderChatThreadPage(
|
||||
botHandle: string,
|
||||
userProfile?: Profile | null,
|
||||
botProfile?: Profile | null,
|
||||
pds?: string
|
||||
pds?: string,
|
||||
chatCollection: string = 'ai.syui.log.chat'
|
||||
): string {
|
||||
const thread = renderChatThread(messages, rootRkey, userDid, userHandle, botDid, botHandle, userProfile, botProfile, pds)
|
||||
const thread = renderChatThread(messages, rootRkey, userDid, userHandle, botDid, botHandle, userProfile, botProfile, pds, chatCollection)
|
||||
return `<div class="chat-container">${thread}</div>`
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
export function renderFooter(handle: string): string {
|
||||
export function renderFooter(handle: string, repoUrl?: string): string {
|
||||
// Extract username from handle: {username}.{name}.{domain} -> username
|
||||
const username = handle.split('.')[0] || handle
|
||||
const repo = repoUrl || '#'
|
||||
|
||||
return `
|
||||
<footer id="footer" class="footer">
|
||||
<div class="license">
|
||||
<a href="https://git.syui.ai/ai/log" target="_blank" rel="noopener">
|
||||
<a href="${repo}" target="_blank" rel="noopener">
|
||||
<img src="/ai.svg" alt="ai" class="license-icon">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -34,21 +34,21 @@ function filterCollectionsByService(collections: string[], service: string): str
|
||||
async function getWebUrl(handle: string): Promise<string | undefined> {
|
||||
const networks = await getNetworks()
|
||||
// Check each network for matching handle domain
|
||||
for (const [domain, network] of Object.entries(networks)) {
|
||||
// Direct domain match (e.g., handle.syu.is -> syu.is)
|
||||
if (handle.endsWith(`.${domain}`)) {
|
||||
return network.web
|
||||
for (const [_domain, network] of Object.entries(networks)) {
|
||||
// Check handleDomains if configured
|
||||
if (network.handleDomains) {
|
||||
for (const hd of network.handleDomains) {
|
||||
if (handle.endsWith(`.${hd}`)) {
|
||||
return network.web
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if handle domain matches network's web domain (e.g., syui.syui.ai -> syu.is via web: syu.is)
|
||||
// Check if handle domain matches network's web domain
|
||||
const webDomain = network.web?.replace(/^https?:\/\//, '')
|
||||
if (webDomain && handle.endsWith(`.${webDomain}`)) {
|
||||
return network.web
|
||||
}
|
||||
}
|
||||
// Check for syui.ai handles -> syu.is network
|
||||
if (handle.endsWith('.syui.ai')) {
|
||||
return networks['syu.is']?.web
|
||||
}
|
||||
// Default to first network's web
|
||||
const firstNetwork = Object.values(networks)[0]
|
||||
return firstNetwork?.web
|
||||
@@ -127,7 +127,7 @@ async function render(route: Route): Promise<void> {
|
||||
app.innerHTML = `
|
||||
${renderHeader(handle, oauthEnabled)}
|
||||
<div class="error">Could not resolve handle: ${handle}</div>
|
||||
${renderFooter(handle)}
|
||||
${renderFooter(handle, config.repoUrl)}
|
||||
`
|
||||
setupEventHandlers()
|
||||
return
|
||||
@@ -230,13 +230,18 @@ async function render(route: Route): Promise<void> {
|
||||
|
||||
} else if (route.type === 'chat') {
|
||||
// Chat list page - show threads started by this user
|
||||
const aiDid = 'did:plc:6qyecktefllvenje24fcxnie' // ai.syui.ai
|
||||
const aiHandle = 'ai.syui.ai'
|
||||
if (!config.bot) {
|
||||
html += `<div id="content" class="error">Bot not configured in config.json</div>`
|
||||
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
||||
} else {
|
||||
const botDid = config.bot.did
|
||||
const botHandle = config.bot.handle
|
||||
const chatCollection = config.chatCollection || 'ai.syui.log.chat'
|
||||
|
||||
// Load messages and profiles in parallel
|
||||
const [chatMessages, aiProfile, pds] = await Promise.all([
|
||||
getChatMessages(did, aiDid, 'ai.syui.log.chat'),
|
||||
getProfile(aiDid, false),
|
||||
const [chatMessages, botProfile, pds] = await Promise.all([
|
||||
getChatMessages(did, botDid, chatCollection),
|
||||
getProfile(botDid, false),
|
||||
getPds(did)
|
||||
])
|
||||
|
||||
@@ -254,18 +259,24 @@ async function render(route: Route): Promise<void> {
|
||||
langList = Array.from(chatLangs)
|
||||
|
||||
html += renderLangSelector(langList)
|
||||
html += `<div id="content">${renderChatListPage(chatMessages, did, handle, aiDid, aiHandle, profile, aiProfile, pds || undefined)}</div>`
|
||||
html += `<div id="content">${renderChatListPage(chatMessages, did, handle, botDid, botHandle, profile, botProfile, pds || undefined)}</div>`
|
||||
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
||||
}
|
||||
|
||||
} else if (route.type === 'chat-thread' && route.rkey) {
|
||||
// Chat thread page - show full conversation
|
||||
const aiDid = 'did:plc:6qyecktefllvenje24fcxnie' // ai.syui.ai
|
||||
const aiHandle = 'ai.syui.ai'
|
||||
if (!config.bot) {
|
||||
html += `<div id="content" class="error">Bot not configured in config.json</div>`
|
||||
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
||||
} else {
|
||||
const botDid = config.bot.did
|
||||
const botHandle = config.bot.handle
|
||||
const chatCollection = config.chatCollection || 'ai.syui.log.chat'
|
||||
|
||||
// Load messages and profiles in parallel
|
||||
const [chatMessages, aiProfile, pds] = await Promise.all([
|
||||
getChatMessages(did, aiDid, 'ai.syui.log.chat'),
|
||||
getProfile(aiDid, false),
|
||||
const [chatMessages, botProfile, pds] = await Promise.all([
|
||||
getChatMessages(did, botDid, chatCollection),
|
||||
getProfile(botDid, false),
|
||||
getPds(did)
|
||||
])
|
||||
|
||||
@@ -283,8 +294,9 @@ async function render(route: Route): Promise<void> {
|
||||
langList = Array.from(chatLangs)
|
||||
|
||||
html += renderLangSelector(langList)
|
||||
html += `<div id="content">${renderChatThreadPage(chatMessages, route.rkey, did, handle, aiDid, aiHandle, profile, aiProfile, pds || undefined)}</div>`
|
||||
html += `<div id="content">${renderChatThreadPage(chatMessages, route.rkey, did, handle, botDid, botHandle, profile, botProfile, pds || undefined, chatCollection)}</div>`
|
||||
html += `<nav class="back-nav"><a href="/@${handle}/at/chat">chat</a></nav>`
|
||||
}
|
||||
|
||||
} else {
|
||||
// User page: compact collection buttons + posts
|
||||
@@ -298,7 +310,7 @@ async function render(route: Route): Promise<void> {
|
||||
html += `<div id="content">${renderPostList(posts, handle)}</div>`
|
||||
}
|
||||
|
||||
html += renderFooter(handle)
|
||||
html += renderFooter(handle, config.repoUrl)
|
||||
|
||||
app.innerHTML = html
|
||||
hideLoading(app)
|
||||
@@ -349,7 +361,7 @@ async function render(route: Route): Promise<void> {
|
||||
app.innerHTML = `
|
||||
${renderHeader(currentHandle, false)}
|
||||
<div class="error">Error: ${error}</div>
|
||||
${renderFooter(currentHandle)}
|
||||
${renderFooter(currentHandle, undefined)}
|
||||
`
|
||||
hideLoading(app)
|
||||
setupEventHandlers()
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
// Config types
|
||||
export interface BotConfig {
|
||||
did: string
|
||||
handle: string
|
||||
}
|
||||
|
||||
export interface AppConfig {
|
||||
title: string
|
||||
did?: string
|
||||
handle: string
|
||||
bot?: BotConfig
|
||||
collection: string
|
||||
chatCollection?: string
|
||||
network: string
|
||||
color: string
|
||||
siteUrl: string
|
||||
repoUrl?: string
|
||||
oauth?: boolean
|
||||
}
|
||||
|
||||
@@ -15,6 +23,7 @@ export interface Networks {
|
||||
plc: string
|
||||
bsky: string
|
||||
web: string
|
||||
handleDomains?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user