Files
assistant-ui--assistant-ui/api-surface/assistant-ui__react-hook-form.ts
wehub-resource-sync e30e75b5d4
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
Changesets / Create Version PR (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

421 lines
12 KiB
TypeScript

import "@standard-schema/spec";
import { ComponentType } from "react";
import { FieldValues, UseFormProps, UseFormReturn } from "react-hook-form";
import { z } from "zod";
type BaseAttachment = {
id: string;
type: "image" | "document" | "file" | (string & {});
name: string;
contentType?: string | undefined;
file?: File;
content?: ThreadUserMessagePart[];
};
type BaseThreadMessage = {
readonly status?: ThreadAssistantMessage["status"];
readonly metadata: {
readonly unstable_state?: ReadonlyJSONValue;
readonly unstable_annotations?: readonly ReadonlyJSONValue[];
readonly unstable_data?: readonly ReadonlyJSONValue[];
readonly steps?: readonly ThreadStep[];
readonly submittedFeedback?: {
readonly type: "negative" | "positive";
};
readonly timing?: MessageTiming;
readonly isOptimistic?: boolean;
readonly custom: Record<string, unknown>;
};
readonly attachments?: ThreadUserMessage["attachments"];
};
type CompleteAttachment = BaseAttachment & {
status: CompleteAttachmentStatus;
content: ThreadUserMessagePart[];
};
type CompleteAttachmentStatus = {
type: "complete";
};
type DataMessagePart<T = any> = {
readonly type: "data";
readonly name: string;
readonly data: T;
};
type FileMessagePart = {
readonly type: "file";
readonly filename?: string;
readonly data: string;
readonly mimeType: string;
readonly parentId?: string;
};
type GenerativeUIMessagePart = {
readonly type: "generative-ui";
readonly spec: GenerativeUISpec;
readonly id?: string;
readonly parentId?: string;
};
type GenerativeUINode = string | {
readonly component: string;
readonly props?: Record<string, unknown>;
readonly children?: readonly GenerativeUINode[];
readonly key?: string;
};
type GenerativeUISpec = {
readonly root: GenerativeUINode | readonly GenerativeUINode[];
};
type ImageMessagePart = {
readonly type: "image";
readonly image: string;
readonly filename?: string;
};
type McpAppMetadata = {
readonly resourceUri: string;
readonly mimeType?: string;
readonly visibility?: readonly ("app" | "model")[];
};
type MessageCommonProps = {
readonly id: string;
readonly createdAt: Date;
};
type MessagePartState = (ThreadUserMessagePart | ThreadAssistantMessagePart) & {
readonly status: MessagePartStatus | ToolCallMessagePartStatus;
};
type MessagePartStatus = {
readonly type: "running";
} | {
readonly type: "complete";
} | {
readonly type: "incomplete";
readonly reason: "cancelled" | "content-filter" | "error" | "length" | "other";
readonly error?: unknown;
};
type MessageStatus = {
readonly type: "running";
} | {
readonly type: "requires-action";
readonly reason: "interrupt" | "tool-calls";
} | {
readonly type: "complete";
readonly reason: "stop" | "unknown";
} | {
readonly type: "incomplete";
readonly reason: "cancelled" | "content-filter" | "error" | "length" | "other" | "tool-calls";
readonly error?: ReadonlyJSONValue;
};
type MessageTiming = {
readonly streamStartTime: number;
readonly firstTokenTime?: number;
readonly totalStreamTime?: number;
readonly tokenCount?: number;
readonly tokensPerSecond?: number;
readonly totalChunks: number;
readonly toolCallCount: number;
};
type PartProviderMetadata = {
readonly [providerName: string]: ReadonlyJSONObject;
};
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
type ReadonlyJSONObject = {
readonly [key: string]: ReadonlyJSONValue;
};
type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
type ReasoningMessagePart = {
readonly type: "reasoning";
readonly text: string;
readonly providerMetadata?: PartProviderMetadata;
readonly parentId?: string;
};
type SourceMessagePart = {
readonly type: "source";
readonly sourceType: "url";
readonly id: string;
readonly url: string;
readonly title?: string;
readonly providerMetadata?: SourceProviderMetadata;
readonly parentId?: string;
} | {
readonly type: "source";
readonly sourceType: "document";
readonly id: string;
readonly url?: undefined;
readonly title: string;
readonly mediaType: string;
readonly filename?: string;
readonly providerMetadata?: SourceProviderMetadata;
readonly parentId?: string;
};
type SourceProviderMetadata = PartProviderMetadata;
interface SpeechRecognitionConstructor {
new (): SpeechRecognitionInstance;
}
interface SpeechRecognitionInstance extends EventTarget {
lang: string;
continuous: boolean;
interimResults: boolean;
start(): void;
stop(): void;
abort(): void;
}
declare const TOOL_RESPONSE_SYMBOL: unique symbol;
type TextMessagePart = {
readonly type: "text";
readonly text: string;
readonly providerMetadata?: PartProviderMetadata;
readonly parentId?: string;
};
type ThreadAssistantMessage = MessageCommonProps & {
readonly role: "assistant";
readonly content: readonly ThreadAssistantMessagePart[];
readonly status: MessageStatus;
readonly metadata: {
readonly unstable_state: ReadonlyJSONValue;
readonly unstable_annotations: readonly ReadonlyJSONValue[];
readonly unstable_data: readonly ReadonlyJSONValue[];
readonly steps: readonly ThreadStep[];
readonly submittedFeedback?: {
readonly type: "negative" | "positive";
};
readonly timing?: MessageTiming;
readonly isOptimistic?: boolean;
readonly custom: Record<string, unknown>;
};
};
type ThreadAssistantMessagePart = TextMessagePart | ReasoningMessagePart | ToolCallMessagePart | SourceMessagePart | FileMessagePart | ImageMessagePart | DataMessagePart | GenerativeUIMessagePart;
type ThreadMessage = BaseThreadMessage & (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);
type ThreadStep = {
readonly messageId?: string;
readonly usage?: {
readonly inputTokens: number;
readonly outputTokens: number;
} | undefined;
};
type ThreadSystemMessage = MessageCommonProps & {
readonly role: "system";
readonly content: readonly [
TextMessagePart
];
readonly metadata: {
readonly unstable_state?: undefined;
readonly unstable_annotations?: undefined;
readonly unstable_data?: undefined;
readonly steps?: undefined;
readonly submittedFeedback?: undefined;
readonly timing?: undefined;
readonly custom: Record<string, unknown>;
};
};
type ThreadUserMessage = MessageCommonProps & {
readonly role: "user";
readonly content: readonly ThreadUserMessagePart[];
readonly attachments: readonly CompleteAttachment[];
readonly metadata: {
readonly unstable_state?: undefined;
readonly unstable_annotations?: undefined;
readonly unstable_data?: undefined;
readonly steps?: undefined;
readonly submittedFeedback?: undefined;
readonly timing?: undefined;
readonly custom: Record<string, unknown>;
};
};
type ThreadUserMessagePart = TextMessagePart | ImageMessagePart | FileMessagePart | DataMessagePart | Unstable_AudioMessagePart;
type ToolApprovalOption = {
readonly id: string;
readonly kind: ToolApprovalOptionKind | (string & {});
readonly label?: string;
readonly description?: string;
readonly grants?: readonly string[];
readonly confirm?: boolean | {
title?: string;
description?: string;
};
};
type ToolApprovalOptionKind = "allow-always" | "allow-once" | "reject-always" | "reject-once";
type ToolApprovalResponse = {
readonly approved: boolean;
readonly reason?: string;
} | {
readonly optionId: string;
readonly reason?: string;
} | {
readonly approved: boolean;
readonly optionId: string;
readonly reason?: string;
};
type ToolCallMessagePart<TArgs = ReadonlyJSONObject, TResult = unknown> = {
readonly type: "tool-call";
readonly toolCallId: string;
readonly toolName: string;
readonly args: TArgs;
readonly result?: TResult | undefined;
readonly isError?: boolean | undefined;
readonly argsText: string;
readonly artifact?: unknown;
readonly timing?: ToolCallTiming;
readonly mcp?: ToolCallMessagePartMcpMetadata;
readonly providerMetadata?: PartProviderMetadata;
readonly modelContent?: readonly ToolModelContentPart[] | undefined;
readonly interrupt?: {
type: "human";
payload: unknown;
};
readonly approval?: {
readonly id: string;
readonly approved?: boolean;
readonly reason?: string;
readonly isAutomatic?: boolean;
readonly options?: readonly ToolApprovalOption[];
readonly optionId?: string;
readonly resolution?: "cancelled" | "expired";
};
readonly parentId?: string;
readonly messages?: readonly ThreadMessage[];
};
type ToolCallMessagePartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallMessagePartProps<TArgs, TResult>>;
type ToolCallMessagePartMcpMetadata = {
readonly app?: McpAppMetadata;
};
type ToolCallMessagePartProps<TArgs = any, TResult = unknown> = MessagePartState & ToolCallMessagePart<TArgs, TResult> & {
addResult: (result: TResult | ToolResponse<TResult>) => void;
resume: (payload: unknown) => void;
respondToApproval: (response: ToolApprovalResponse) => void;
};
type ToolCallMessagePartStatus = {
readonly type: "requires-action";
readonly reason: "interrupt";
} | MessagePartStatus;
type ToolCallTiming = {
readonly startedAt: number;
readonly completedAt?: number;
};
type ToolModelContentPart = {
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly data: string;
readonly mediaType: string;
readonly filename?: string;
};
declare class ToolResponse<TResult> {
get [TOOL_RESPONSE_SYMBOL](): boolean;
readonly artifact?: ReadonlyJSONValue;
readonly result: TResult;
readonly isError: boolean;
readonly modelContent?: readonly ToolModelContentPart[];
readonly messages?: ReadonlyJSONValue;
constructor(options: ToolResponseLike<TResult>);
static [Symbol.hasInstance](obj: unknown): obj is ToolResponse<ReadonlyJSONValue>;
static toResponse(result: any | ToolResponse<any>): ToolResponse<any>;
}
type ToolResponseLike<TResult> = {
result: TResult;
artifact?: ReadonlyJSONValue | undefined;
isError?: boolean | undefined;
modelContent?: readonly ToolModelContentPart[] | undefined;
messages?: ReadonlyJSONValue | undefined;
};
type Unstable_AudioMessagePart = {
readonly type: "audio";
readonly audio: {
readonly data: string;
readonly format: "mp3" | "wav";
};
};
type UseAssistantFormProps<TFieldValues extends FieldValues, TContext, TTransformedValues> = UseFormProps<TFieldValues, TContext, TTransformedValues> & {
assistant?: {
tools?: {
set_form_field?: {
render?: ToolCallMessagePartComponent<z.infer<(typeof formTools.set_form_field)["parameters"]>, unknown> | undefined;
} | undefined;
submit_form?: {
render?: ToolCallMessagePartComponent<z.infer<(typeof formTools.submit_form)["parameters"]>, unknown> | undefined;
} | undefined;
reset_form?: {
render?: ToolCallMessagePartComponent<z.infer<(typeof formTools.reset_form)["parameters"]>, unknown> | undefined;
} | undefined;
} | undefined;
} | undefined;
};
declare const formTools: {
set_form_field: {
description: string;
parameters: z.ZodObject<{
name: z.ZodString;
value: z.ZodString;
}, z.core.$strip>;
};
submit_form: {
description: string;
parameters: z.ZodObject<{}, z.core.$strip>;
};
reset_form: {
description: string;
parameters: z.ZodObject<{}, z.core.$strip>;
};
};
declare global {
interface Window {
SpeechRecognition?: SpeechRecognitionConstructor;
webkitSpeechRecognition?: SpeechRecognitionConstructor;
}
}
declare namespace entry_root_exports {
export { UseAssistantFormProps, formTools, useAssistantForm };
}
declare const useAssistantForm: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>(props?: UseAssistantFormProps<TFieldValues, TContext, TTransformedValues>) => UseFormReturn<TFieldValues, TContext, TTransformedValues>;
export { entry_root_exports as entry_root };