Files
wehub-resource-sync e30e75b5d4
Changesets / Create Version PR (push) Waiting to run
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
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

566 lines
18 KiB
TypeScript

import "@radix-ui/react-primitive";
import { StandardSchemaV1 } from "@standard-schema/spec";
import "radix-ui";
import { CSSProperties, ComponentType, ReactNode } from "react";
import "react-textarea-autosize";
import "zustand";
type AncestorsOf<K extends ClientNames, Seen extends ClientNames = never> = K extends Seen ? never : ParentOf<K> extends never ? never : ParentOf<K> | AncestorsOf<ParentOf<K>, Seen | K>;
interface ApiInfo {
id: number;
state: Record<string, unknown>;
logs: EventLogEntry[];
modelContext?: SerializedModelContext | undefined;
scopes?: unknown;
threadSnapshots?: Readonly<Record<string, unknown>>;
}
type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;
type AssistantClient = {
[K in ClientNames]: AssistantClientAccessor<K>;
} & {
subscribe(listener: () => void): Unsubscribe;
on<TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>): Unsubscribe;
};
type AssistantClientAccessor<K extends ClientNames> = (() => ClientSchemas[K]["methods"]) & (ClientMeta<K> | {
source: "root";
query: Record<string, never>;
} | {
source: null;
query: null;
}) & {
name: K;
};
type AssistantEventCallback<TEvent extends AssistantEventName> = (payload: AssistantEventPayload[TEvent]) => void;
type AssistantEventName = keyof AssistantEventPayload;
type AssistantEventPayload = ClientEventMap & {
"*": WildcardPayload;
};
type AssistantEventScope<TEvent extends AssistantEventName> = "*" | EventSource<TEvent> | (EventSource<TEvent> extends ClientNames ? AncestorsOf<EventSource<TEvent>> : never);
type AssistantEventSelector<TEvent extends AssistantEventName> = TEvent | {
scope: AssistantEventScope<TEvent>;
event: TEvent;
};
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
type: "backend";
description?: undefined;
parameters?: undefined;
disabled?: undefined;
execute?: undefined;
toModelOutput?: undefined;
experimental_onSchemaValidationError?: undefined;
providerOptions?: undefined;
};
type ClientError<E extends string> = {
methods: Record<E, () => E>;
meta: {
source: ClientNames;
query: Record<E, E>;
};
events: Record<`${E}.`, E>;
};
type ClientEventMap = UnionToIntersection<{
[K in ClientNames]: ClientEvents<K>;
}[ClientNames]>;
type ClientEvents<K extends ClientNames> = "events" extends keyof ClientSchemas[K] ? ClientSchemas[K]["events"] extends ClientEventsType<K> ? ClientSchemas[K]["events"] : never : never;
type ClientEventsType<K extends ClientNames> = Record<`${K}.${string}`, unknown>;
type ClientMeta<K extends ClientNames> = "meta" extends keyof ClientSchemas[K] ? Pick<ClientSchemas[K]["meta"] extends ClientMetaType ? ClientSchemas[K]["meta"] : never, "query" | "source"> : never;
type ClientMetaType = {
source: ClientNames;
query: Record<string, unknown>;
};
interface ClientMethods {
[key: string | symbol]: (...args: any[]) => any;
}
type ClientNames = keyof ClientSchemas extends (infer U) ? U : never;
type ClientSchemas = keyof ScopeRegistry extends never ? {
"ERROR: No clients were defined": ClientError<"ERROR: No clients were defined">;
} : {
[K in keyof ScopeRegistry]: ValidateClient<K>;
};
type DeepPartial<T> = T extends readonly any[] ? readonly DeepPartial<T[number]>[] : T extends {
[key: string]: any;
} ? {
readonly [K in keyof T]?: DeepPartial<T[K]>;
} : T;
interface DevToolsApiEntry {
api: Partial<AssistantClient>;
logs: EventLog[];
}
interface DevToolsClient {
subscribe(listener: () => void): () => void;
getSnapshot(): DevToolsSnapshot;
getServerSnapshot?(): DevToolsSnapshot;
clearEvents(apiId: number): void;
switchToThread?(apiId: number, threadId: string): void | Promise<void>;
}
interface DevToolsHook {
apis: Map<number, DevToolsApiEntry>;
nextId: number;
listeners: Set<(apiId: number) => void>;
}
declare const DevToolsModal: (props?: DevToolsModalProps) => import("react").JSX.Element | null;
interface DevToolsModalProps {
plugins?: DevToolsPanelPlugin[];
theme?: "dark" | "light" | "system";
client?: DevToolsClient;
}
declare const DevToolsPanel: (_param0: DevToolsPanelProps) => import("react").JSX.Element;
interface DevToolsPanelPlugin {
id: string;
label: string;
order?: number;
isAvailable?: (ctx: DevToolsTabContext) => boolean;
Component: ComponentType<DevToolsTabContext>;
}
interface DevToolsPanelProps {
plugins?: DevToolsPanelPlugin[] | undefined;
theme?: "dark" | "light";
onClose?: (() => void) | undefined;
client?: DevToolsClient | undefined;
}
interface DevToolsSnapshot {
apiIds: number[];
byId: ReadonlyMap<number, ApiInfo>;
}
interface DevToolsTabContext {
apiId: number;
data: ApiInfo;
clearEvents: (apiId: number) => void;
theme: "dark" | "light";
selection: string | null;
setSelection: (nodeId: string | null) => void;
switchToThread?: ((threadId: string) => void | Promise<void>) | undefined;
}
interface EventLog {
time: Date;
event: string;
data: unknown;
}
interface EventLogEntry {
readonly time: Date;
readonly event: string;
readonly data: unknown;
}
type EventSource<T extends AssistantEventName> = T extends `${infer Source}.${string}` ? Source : never;
type FrontendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
type: "frontend";
description?: string | undefined;
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
disabled?: boolean;
execute?: ToolExecuteFunction<TArgs, TResult>;
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
providerOptions?: ProviderOptions;
};
type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
type: "human";
description?: string | undefined;
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
disabled?: boolean;
display?: "standalone";
execute?: undefined;
toModelOutput?: undefined;
experimental_onSchemaValidationError?: undefined;
providerOptions?: ProviderOptions;
};
interface JSONSchema7 {
$id?: string | undefined;
$ref?: string | undefined;
$schema?: JSONSchema7Version | undefined;
$comment?: string | undefined;
$defs?: {
[key: string]: JSONSchema7Definition;
} | undefined;
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
enum?: JSONSchema7Type[] | undefined;
const?: JSONSchema7Type | undefined;
multipleOf?: number | undefined;
maximum?: number | undefined;
exclusiveMaximum?: number | undefined;
minimum?: number | undefined;
exclusiveMinimum?: number | undefined;
maxLength?: number | undefined;
minLength?: number | undefined;
pattern?: string | undefined;
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
additionalItems?: JSONSchema7Definition | undefined;
maxItems?: number | undefined;
minItems?: number | undefined;
uniqueItems?: boolean | undefined;
contains?: JSONSchema7Definition | undefined;
maxProperties?: number | undefined;
minProperties?: number | undefined;
required?: string[] | undefined;
properties?: {
[key: string]: JSONSchema7Definition;
} | undefined;
patternProperties?: {
[key: string]: JSONSchema7Definition;
} | undefined;
additionalProperties?: JSONSchema7Definition | undefined;
dependencies?: {
[key: string]: JSONSchema7Definition | string[];
} | undefined;
propertyNames?: JSONSchema7Definition | undefined;
if?: JSONSchema7Definition | undefined;
then?: JSONSchema7Definition | undefined;
else?: JSONSchema7Definition | undefined;
allOf?: JSONSchema7Definition[] | undefined;
anyOf?: JSONSchema7Definition[] | undefined;
oneOf?: JSONSchema7Definition[] | undefined;
not?: JSONSchema7Definition | undefined;
format?: string | undefined;
contentMediaType?: string | undefined;
contentEncoding?: string | undefined;
definitions?: {
[key: string]: JSONSchema7Definition;
} | undefined;
title?: string | undefined;
description?: string | undefined;
default?: JSONSchema7Type | undefined;
readOnly?: boolean | undefined;
writeOnly?: boolean | undefined;
examples?: JSONSchema7Type | undefined;
}
interface JSONSchema7Array extends Array<JSONSchema7Type> {
}
type JSONSchema7Definition = JSONSchema7 | boolean;
interface JSONSchema7Object {
[key: string]: JSONSchema7Type;
}
type JSONSchema7Type = string | number | boolean | JSONSchema7Object | JSONSchema7Array | null;
type JSONSchema7TypeName = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string";
type JSONSchema7Version = string;
type LanguageModelConfig = {
apiKey?: string;
baseUrl?: string;
modelName?: string;
reasoningEffort?: string;
};
type LanguageModelV1CallSettings = {
maxTokens?: number;
temperature?: number;
topP?: number;
presencePenalty?: number;
frequencyPenalty?: number;
seed?: number;
headers?: Record<string, string | undefined>;
};
type McpServerConfig = {
type: "http" | "sse";
url: string;
headers?: Record<string, string>;
redirect?: "error" | "follow";
connectionTimeout?: number | undefined;
} | {
type: "stdio";
command: string;
args?: readonly string[];
env?: Record<string, string>;
cwd?: string;
connectionTimeout?: number | undefined;
};
type McpTool = ToolBase<Record<string, unknown>, unknown> & {
type: "mcp";
server: McpServerConfig;
description?: undefined;
parameters?: undefined;
disabled?: boolean;
execute?: undefined;
toModelOutput?: undefined;
experimental_onSchemaValidationError?: undefined;
providerOptions?: undefined;
};
type ModelContext = {
priority?: number | undefined;
system?: string | undefined;
tools?: Record<string, Tool<any, any>> | undefined;
callSettings?: LanguageModelV1CallSettings | undefined;
config?: LanguageModelConfig | undefined;
unstable_composerMetadata?: Record<string, unknown> | undefined;
};
type NormalizedTool = {
name: string;
type?: string;
description?: string;
disabled?: boolean;
display?: string;
providerId?: string;
supportsDeferredResults?: boolean;
backendDefault?: unknown;
providerOptions?: unknown;
providerArgs?: unknown;
server?: unknown;
parameters?: unknown;
};
type ObjectKey<T> = keyof T & (string | number);
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
type ParentOf<K extends ClientNames> = AssistantClientAccessor<K> extends {
source: infer S;
} ? S extends ClientNames ? S : never : never;
type ProviderOptions = Record<string, Record<string, unknown>>;
type ProviderTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
type: "provider";
providerId: `${string}.${string}`;
parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
args: Record<string, unknown>;
supportsDeferredResults?: boolean;
description?: undefined;
disabled?: boolean;
execute?: undefined;
toModelOutput?: undefined;
experimental_onSchemaValidationError?: undefined;
providerOptions?: ProviderOptions;
};
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
type ReadonlyJSONObject = {
readonly [key: string]: ReadonlyJSONValue;
};
type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
interface ScopeRegistry {
[key: string]: { methods: any; meta?: any; events?: any };
}
interface SerializedModelContext {
system?: string;
tools?: NormalizedTool[];
callSettings?: Record<string, unknown>;
config?: Record<string, unknown>;
}
declare const ShadowRoot: (_param1: ShadowRootProps) => import("react").JSX.Element;
interface ShadowRootProps {
theme: "dark" | "light";
className?: string;
style?: CSSProperties;
children: ReactNode;
}
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 Tool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = FrontendTool<TArgs, TResult> | BackendTool<TArgs, TResult> | HumanTool<TArgs, TResult> | ProviderTool<TArgs, TResult> | McpTool | ToolWithoutType<TArgs, TResult>;
type ToolBase<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = {
streamCall?: ToolStreamCallFunction<TArgs, TResult>;
display?: ToolDisplay;
};
interface ToolCallArgsReader<TArgs extends Record<string, unknown>> {
get<PathT extends TypePath<TArgs>>(...fieldPath: PathT): Promise<TypeAtPath<TArgs, PathT>>;
streamValues<PathT extends TypePath<TArgs>>(...fieldPath: PathT): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;
streamText<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends string & (infer U) ? AsyncIterableStream<U> : never;
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): NonNullable<TypeAtPath<TArgs, PathT>> extends Array<infer U> ? AsyncIterableStream<U> : never;
}
interface ToolCallReader<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> {
args: ToolCallArgsReader<TArgs>;
response: ToolCallResponseReader<TResult>;
result: {
get: () => Promise<TResult>;
};
}
interface ToolCallResponseReader<TResult> {
get: () => Promise<ToolResponse<TResult>>;
}
type ToolDisplay = "inline" | "standalone";
type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>;
type ToolExecutionContext = {
toolCallId: string;
abortSignal: AbortSignal;
human: (payload: unknown) => Promise<unknown>;
};
type ToolModelContentPart = {
readonly type: "text";
readonly text: string;
} | {
readonly type: "file";
readonly data: string;
readonly mediaType: string;
readonly filename?: string;
};
type ToolModelOutputFunction<TArgs, TResult> = (options: {
toolCallId: string;
input: TArgs;
output: TResult;
}) => readonly ToolModelContentPart[] | Promise<readonly ToolModelContentPart[]>;
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 ToolStreamCallFunction<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecutionContext) => void;
type ToolWithoutType<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (Omit<FrontendTool<TArgs, TResult>, "type"> | Omit<BackendTool<TArgs, TResult>, "type"> | Omit<HumanTool<TArgs, TResult>, "type"> | Omit<ProviderTool<TArgs, TResult>, "type">) & {
type?: undefined;
};
type TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
type TypeAtPath<T, P extends readonly any[]> = P extends [
infer Head,
...infer Rest
] ? Head extends keyof T ? TypeAtPath<T[Head], Rest> : never : T;
type TypePath<T> = [
] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? {
[K in TupleIndex<T>]: [
AsNumber<K>,
...TypePath<T[K]>
];
}[TupleIndex<T>] : [
number,
...TypePath<T[number]>
] : {
[K in ObjectKey<T>]: [
K,
...TypePath<T[K]>
];
}[ObjectKey<T>] : [
]);
type UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
type Unsubscribe = () => void;
type ValidateClient<K extends keyof ScopeRegistry> = ScopeRegistry[K] extends {
methods: ClientMethods;
} ? "meta" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["meta"] extends ClientMetaType ? "events" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["events"] extends ClientEventsType<K> ? ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid events type`> : ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid meta type`> : "events" extends keyof ScopeRegistry[K] ? ScopeRegistry[K]["events"] extends ClientEventsType<K> ? ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid events type`> : ScopeRegistry[K] : ClientError<`ERROR: ${K & string} has invalid methods type`>;
type WildcardPayload = {
[K in keyof ClientEventMap]: {
event: K;
payload: ClientEventMap[K];
};
}[Extract<keyof ClientEventMap, string>];
declare const builtinPlugins: DevToolsPanelPlugin[];
declare const createDevToolsPlugin: (plugin: DevToolsPanelPlugin) => DevToolsPanelPlugin;
declare const createInProcessClient: () => DevToolsClient;
declare global {
interface Window {
SpeechRecognition?: SpeechRecognitionConstructor;
webkitSpeechRecognition?: SpeechRecognitionConstructor;
}
}
declare global {
interface Window {
__ASSISTANT_UI_DEVTOOLS_HOOK__?: any;
}
}
declare const inProcessClient: DevToolsClient;
declare namespace entry_root_exports {
export { ApiInfo, DevToolsClient, DevToolsModal, DevToolsModalProps, DevToolsPanel, DevToolsPanelPlugin, DevToolsPanelProps, DevToolsSnapshot, DevToolsTabContext, NormalizedTool, SerializedModelContext, ShadowRoot, builtinPlugins, createDevToolsPlugin, createInProcessClient, inProcessClient, normalizeToolList, serializeModelContext };
}
declare const normalizeToolList: (value: unknown) => NormalizedTool[];
declare const serializeModelContext: (context: ModelContext | undefined) => SerializedModelContext | undefined;
export { entry_root_exports as entry_root };