feat: initialize LineUp Tauri reference host

This commit is contained in:
2026-08-03 10:26:27 +08:00
commit 32a425034b
79 changed files with 11460 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
export const LINEUP_PROTOCOL_VERSION = 1;
export type Envelope = {
v: number;
id?: string;
type: string;
conversation_id?: string;
payload?: unknown;
};
export type ConversationItem =
| { kind: "markdown"; markdown: string; envelope?: Envelope }
| { kind: "agent-status"; status: string; detail: string; envelope?: Envelope }
| { kind: "progress"; title: string; percent: number; status: string; envelope?: Envelope }
| { kind: "error"; message: string; envelope?: Envelope }
| { kind: "surface"; envelope: Envelope }
| { kind: "app-call"; envelope: Envelope }
| { kind: "fallback"; reason: string; envelope?: Envelope };
function object(value: unknown): Record<string, unknown> | null {
return value !== null && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: null;
}
function text(value: unknown): string {
return typeof value === "string" ? value : "";
}
export function decodeConversationItem(raw: string): ConversationItem {
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch {
return { kind: "markdown", markdown: raw };
}
const envelope = object(parsed) as Envelope | null;
if (!envelope || envelope.v !== LINEUP_PROTOCOL_VERSION || !envelope.type?.startsWith("lineup.v1.")) {
return { kind: "fallback", reason: "invalid_envelope" };
}
const payload = object(envelope.payload) ?? {};
switch (envelope.type) {
case "lineup.v1.text":
return { kind: "markdown", markdown: text(payload.markdown) || text(payload.text), envelope };
case "lineup.v1.agent.status":
return { kind: "agent-status", status: text(payload.status), detail: text(payload.detail), envelope };
case "lineup.v1.agent.progress":
return { kind: "progress", title: text(payload.title), percent: Number(payload.percent) || 0, status: text(payload.status), envelope };
case "lineup.v1.error":
return { kind: "error", message: text(payload.message) || "Agent 执行失败", envelope };
case "lineup.v1.ui.open":
case "lineup.v1.ui.patch":
case "lineup.v1.ui.close":
return { kind: "surface", envelope };
case "lineup.v1.app.call":
return { kind: "app-call", envelope };
default:
return { kind: "fallback", reason: "unsupported_type", envelope };
}
}