Merge pull request #106 from RuoJi6/codex/btw-side-question
feat: add /btw side questions
This commit is contained in:
41 files changed
+4976
-318
No files matched your search
+1
-1
@@ -99,7 +99,7 @@ function getToken(): string | null {
|
||||
return localStorage.getItem("artex_token");
|
||||
}
|
||||
|
||||
async function http<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
export async function http<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
if (MOCK) return mockHandle<T>(init?.method ?? "GET", path, init?.body ?? null);
|
||||
const token = getToken();
|
||||
const r = await fetch(`/api${path}`, {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { http } from "@/lib/api";
|
||||
|
||||
export interface SideModel {
|
||||
model: string;
|
||||
name: string;
|
||||
format: string;
|
||||
profile_id: number;
|
||||
}
|
||||
export interface SideExchange {
|
||||
id: string;
|
||||
ordinal: number;
|
||||
client_request_id: string;
|
||||
question: string;
|
||||
answer: string;
|
||||
status: "running" | "completed" | "failed" | "cancelled" | "interrupted";
|
||||
error?: string;
|
||||
model: SideModel;
|
||||
snapshot_at: string;
|
||||
created_at: string;
|
||||
sequence: number;
|
||||
context?: {
|
||||
phase?: "preparing" | "summarizing_history" | "compressing_snapshot" | "retrying" | "answering";
|
||||
recent_exchanges: number;
|
||||
history_summarized: boolean;
|
||||
snapshot_summarized: boolean;
|
||||
estimated_input_tokens?: number;
|
||||
input_budget?: number;
|
||||
output_tokens?: number;
|
||||
overflow_retried?: boolean;
|
||||
};
|
||||
}
|
||||
export interface SideHistory {
|
||||
items: SideExchange[];
|
||||
current: SideExchange | null;
|
||||
next_cursor: number;
|
||||
snapshot: { captured_at: string; model: SideModel; available: boolean; reason: string } | null;
|
||||
}
|
||||
|
||||
async function request<T>(path: string, method = "GET", body?: unknown): Promise<T> {
|
||||
return http<T>(path.replace(/^\/api/, ""), { method, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
}
|
||||
|
||||
export const sideAPI = {
|
||||
history: (parent: string, before = 0) => request<SideHistory>(`${parent}/side-questions?before=${before}`),
|
||||
ask: (parent: string, question: string, client_request_id: string) =>
|
||||
request<SideExchange>(`${parent}/side-questions`, "POST", { question, client_request_id }),
|
||||
clear: (parent: string) => request(`${parent}/side-questions`, "DELETE"),
|
||||
cancel: (id: string) => request(`/api/side-questions/${id}/cancel`, "POST"),
|
||||
};
|
||||
|
||||
export function isBtwCommand(text: string) {
|
||||
return /^\/btw(?:\s|$)/.test(text.trim());
|
||||
}
|
||||
Reference in new issue
Block a user