feat: KOOK自动获取bot身份 + action/narration剥出气泡 + 渠道配置表单回填
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

agent-116 KOOK token即用+自动获取:
- kook/identity.go: Connect 调 GET /user/me 拿 bot 身份(bot_id/bot_username/bot_nickname), 失败容错
- 渠道列表 enrichAccountsWithBot 附 bot 身份; base_url空用默认/receive_mode默认ws(只填token可跑)

agent-117 action/narration 剥出气泡(主人需求: 动作/旁白不进气泡,按位置上/下):
- parseContent.splitBubble(content)->{body,head,tail}: body=纯文本(去标签), head=开头/中间action/narr(气泡上), tail=结尾(气泡下)
- renderContent 只渲染text(去内联灰斜体); chat.tsx BubbleNotes 泡外 *动作/旁白* 灰斜体小字(气泡外依附), SplitChatBubble 先剥splitBubble再splitParagraphs(body), <p>/\n\n/毛玻璃/SourceLabel不破坏
- 注: 非chat mode renderContent 现在丢弃action/narr(可接受)

Channels 配置表单回填(修save后输入框空):
- openConfig 从 data.accounts[0].config 回填 token(掩码提示)/base_url/平台字段/黑白名单/限流, 不再硬清空
全仓 build/vet/test绿+前端build绿
This commit is contained in:
Aska committed 2026-09-07 15:31:14 +08:00
1 parent bdd9d752e1
commit 65091f6497
15 files changed
+571 -83

No files matched your search

+58 -2
View File
@@ -1,8 +1,9 @@
// Structured parser for persona action/narration XML tags (design/07 §1).
// A single message `content` may mix plain text with `<action>…</action>` and
// `<narration>…</narration>`; this splits it into an ordered parts array so the
// UI can render inline (grey italic) while the structured data stays available
// for downstream feeds (mind-map / state) via `summarizeContent`.
// UI can position each block (inline, or as an attachment note via `splitBubble`)
// while the structured data stays available for downstream feeds (mind-map /
// state) via `summarizeContent`.
export type ContentPartType = "text" | "action" | "narration";
@@ -64,3 +65,58 @@ export function summarizeContent(content: string): ContentSummary {
}
return summary;
}
/** Result of `splitBubble`: a renderable plain-text `body` plus the annotation
* blocks that belong above (`head`) or below (`tail`) the bubble. `head`/`tail`
* hold the leading / trailing action & narration parts in order; `body` is the
* concatenated text with any annotation blocks removed. */
export interface BubbleSplit {
body: string;
head: ContentPart[];
tail: ContentPart[];
}
/**
* Peel the `<action>` / `<narration>` blocks out of `content` so the bubble
* body is pure text while the annotations attach as notes outside it.
*
* - `head` = the leading run of action/narration before the FIRST text part
* (rendered above the bubble).
* - `tail` = the trailing run of action/narration after the LAST text part
* (rendered below the bubble).
* - `body` = every text part concatenated and outer-trimmed.
* - Annotation blocks interleaved BETWEEN text paragraphs have no stable text
* anchor once the body collapses, so they lift to `head` — the only hard
* requirement is that they never render inside the bubble.
* - A content with no text part at all yields an empty `body` with everything
* in `head`, so the notes alone carry the message.
*/
export function splitBubble(content: string): BubbleSplit {
const parts = parseContent(content);
let firstTextIdx = -1;
let lastTextIdx = -1;
parts.forEach((part, i) => {
if (part.type === "text") {
if (firstTextIdx < 0) firstTextIdx = i;
lastTextIdx = i;
}
});
const head: ContentPart[] = [];
const tail: ContentPart[] = [];
let bodyText = "";
parts.forEach((part, i) => {
if (part.type === "text") {
bodyText += part.text;
return;
}
if (firstTextIdx < 0 || i < firstTextIdx || (i > firstTextIdx && i < lastTextIdx)) {
head.push(part);
} else {
tail.push(part);
}
});
return { body: bodyText.trim(), head, tail };
}
+7 -15
View File
@@ -1,19 +1,11 @@
import type { ReactNode } from "react";
import { parseContent, type ContentPart } from "../lib/parseContent";
import { parseContent } from "../lib/parseContent";
/** Render a message body into inline parts: plain text as-is, while
* `<action>` / `<narration>` become muted italic spans (Miuix `--mu-text-lo`).
* Whitespace is preserved by the caller's `whitespace-pre-wrap` container — the
* returned nodes are just the segments dropped into it in order. */
/** Render a message body into its plain-text segments only. `<action>` /
* `<narration>` blocks are NOT rendered inline here — they are peeled out by
* `splitBubble` and shown as attachment notes outside the bubble. */
export function renderContent(content: string): ReactNode[] {
return parseContent(content).map((part, i) => renderPart(part, i));
}
function renderPart(part: ContentPart, key: number): ReactNode {
if (part.type === "text") return <span key={key}>{part.text}</span>;
return (
<span key={key} className="italic text-[var(--mu-text-lo)]">
{part.text}
</span>
);
return parseContent(content)
.filter((part) => part.type === "text")
.map((part, i) => <span key={i}>{part.text}</span>);
}
+4
View File
@@ -269,6 +269,10 @@ export interface AdminChannelAccount {
groupMsgPerMin?: number;
msgPerMin?: number;
maxMessages?: number;
/** Connected bot identity (kook resolves it from /api/v3/user/me). */
botId?: string;
botUsername?: string;
botNickname?: string;
}
/** An IoT device as returned by GET /api/v1/admin/iot. */