mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 08:28:36 +00:00
* feat: support document attachments in webui * fix(webui): normalize document attachment MIME * refactor(webui): move attachment policy out of channel * fix(webui): reject oversized attachments before send * fix(webui): align Portuguese attachment errors * refactor(webui): separate ingress and transport limits * fix(webui): reject malformed attachment payloads
42 lines
1002 B
TypeScript
42 lines
1002 B
TypeScript
import { createContext, useContext, type ReactNode } from "react";
|
|
|
|
import type { NanobotClient } from "@/lib/nanobot-client";
|
|
import type { WebUIIngressLimits } from "@/lib/types";
|
|
|
|
interface ClientContextValue {
|
|
client: NanobotClient;
|
|
token: string;
|
|
modelName: string | null;
|
|
ingressLimits: WebUIIngressLimits | null;
|
|
}
|
|
|
|
const ClientContext = createContext<ClientContextValue | null>(null);
|
|
|
|
export function ClientProvider({
|
|
client,
|
|
token,
|
|
modelName = null,
|
|
ingressLimits = null,
|
|
children,
|
|
}: {
|
|
client: NanobotClient;
|
|
token: string;
|
|
modelName?: string | null;
|
|
ingressLimits?: WebUIIngressLimits | null;
|
|
children: ReactNode;
|
|
}) {
|
|
return (
|
|
<ClientContext.Provider value={{ client, token, modelName, ingressLimits }}>
|
|
{children}
|
|
</ClientContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useClient(): ClientContextValue {
|
|
const ctx = useContext(ClientContext);
|
|
if (!ctx) {
|
|
throw new Error("useClient must be used within a ClientProvider");
|
|
}
|
|
return ctx;
|
|
}
|