@june-ai/june-ui 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +66 -3
- package/dist/index.cjs +1126 -0
- package/dist/index.d.cts +256 -0
- package/dist/index.d.ts +256 -0
- package/dist/index.js +1086 -0
- package/dist/june.css +21 -0
- package/package.json +77 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps, Component, ReactNode, ErrorInfo, CSSProperties } from 'react';
|
|
3
|
+
import { Renderer, createLibrary, defineComponent } from '@openuidev/react-lang';
|
|
4
|
+
|
|
5
|
+
type JuneErrorCode = "PARSE_ERROR" | "RENDER_ERROR" | "STREAM_ERROR" | "STREAM_ABORTED" | "STREAM_EMPTY" | "NETWORK_ERROR" | "ACTION_ERROR" | "ACTION_VALIDATION_ERROR" | "ACTION_REJECTED" | "LIBRARY_ERROR";
|
|
6
|
+
interface JuneErrorOptions {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
details?: unknown;
|
|
9
|
+
}
|
|
10
|
+
declare class JuneError extends Error {
|
|
11
|
+
readonly code: JuneErrorCode;
|
|
12
|
+
readonly details?: unknown;
|
|
13
|
+
constructor(code: JuneErrorCode, message: string, options?: JuneErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
declare function isJuneError(value: unknown): value is JuneError;
|
|
16
|
+
declare function toJuneError(error: unknown, fallbackCode: JuneErrorCode, message?: string): JuneError;
|
|
17
|
+
|
|
18
|
+
/** Props of OpenUI's real Renderer. Derived, never hand-copied. */
|
|
19
|
+
type OpenUIRendererProps = ComponentProps<typeof Renderer>;
|
|
20
|
+
/** The library type OpenUI's Renderer accepts. */
|
|
21
|
+
type OpenUILibrary = OpenUIRendererProps["library"];
|
|
22
|
+
/** The event OpenUI passes to onAction. */
|
|
23
|
+
type OpenUIActionEvent = Parameters<NonNullable<OpenUIRendererProps["onAction"]>>[0];
|
|
24
|
+
type JuneThemeMode = "light" | "dark" | "system";
|
|
25
|
+
type JuneResolvedTheme = "light" | "dark";
|
|
26
|
+
|
|
27
|
+
/** Anything with a zod-style safeParse. No hard dependency on zod. */
|
|
28
|
+
interface SchemaLike<T> {
|
|
29
|
+
safeParse(data: unknown): {
|
|
30
|
+
success: true;
|
|
31
|
+
data: T;
|
|
32
|
+
} | {
|
|
33
|
+
success: false;
|
|
34
|
+
error: unknown;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface JuneActionContext {
|
|
38
|
+
name: string;
|
|
39
|
+
/** The raw OpenUI action event. */
|
|
40
|
+
event: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface JuneActionDefinition<TPayload = unknown> {
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Validates the payload before the handler runs. */
|
|
45
|
+
schema?: SchemaLike<TPayload>;
|
|
46
|
+
/** Sensitive actions are denied unless a confirm handler approves them. */
|
|
47
|
+
sensitive?: boolean;
|
|
48
|
+
/** Per-action confirmation; overrides the global confirmAction. */
|
|
49
|
+
confirm?: (args: {
|
|
50
|
+
name: string;
|
|
51
|
+
payload: TPayload;
|
|
52
|
+
description?: string;
|
|
53
|
+
}) => boolean | Promise<boolean>;
|
|
54
|
+
handler: (payload: TPayload, context: JuneActionContext) => void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
type JuneAction<TPayload = unknown> = Readonly<JuneActionDefinition<TPayload>> & {
|
|
57
|
+
readonly __june: "action";
|
|
58
|
+
};
|
|
59
|
+
type JuneActionMap = Record<string, JuneAction<any>>;
|
|
60
|
+
declare function defineJuneAction<TPayload = unknown>(definition: JuneActionDefinition<TPayload>): JuneAction<TPayload>;
|
|
61
|
+
|
|
62
|
+
interface ParsedActionEvent {
|
|
63
|
+
name: string;
|
|
64
|
+
payload: unknown;
|
|
65
|
+
}
|
|
66
|
+
type ActionEventParser = (event: OpenUIActionEvent) => ParsedActionEvent | null;
|
|
67
|
+
type ConfirmAction = (args: {
|
|
68
|
+
name: string;
|
|
69
|
+
payload: unknown;
|
|
70
|
+
description?: string;
|
|
71
|
+
}) => boolean | Promise<boolean>;
|
|
72
|
+
type ActionOutcome = "handled" | "unhandled" | "rejected" | "failed";
|
|
73
|
+
/**
|
|
74
|
+
* BEST-EFFORT default: reads the action name from `type`/`name`/`action` and
|
|
75
|
+
* the payload from `params`/`payload`/`data`. Verify against OpenUI's actual
|
|
76
|
+
* action event type (see the .d.ts) and override with `parseActionEvent`
|
|
77
|
+
* if the shape differs. This is the only place that guesses the event shape.
|
|
78
|
+
*/
|
|
79
|
+
declare const defaultParseActionEvent: ActionEventParser;
|
|
80
|
+
interface RunActionOptions {
|
|
81
|
+
actions: JuneActionMap;
|
|
82
|
+
parseEvent?: ActionEventParser;
|
|
83
|
+
confirm?: ConfirmAction;
|
|
84
|
+
onError?: (error: JuneError) => void;
|
|
85
|
+
onUnhandled?: (event: OpenUIActionEvent) => void;
|
|
86
|
+
}
|
|
87
|
+
/** Looks up and runs a registered action. Never evaluates model-provided code. */
|
|
88
|
+
declare function runAction(event: OpenUIActionEvent, options: RunActionOptions): Promise<ActionOutcome>;
|
|
89
|
+
declare function createActionHandler(options: RunActionOptions): (event: OpenUIActionEvent) => void;
|
|
90
|
+
|
|
91
|
+
type JuneThemeVars = Record<string, string>;
|
|
92
|
+
declare const lightTheme: JuneThemeVars;
|
|
93
|
+
|
|
94
|
+
interface FallbackArgs {
|
|
95
|
+
error: Error;
|
|
96
|
+
reset: () => void;
|
|
97
|
+
}
|
|
98
|
+
interface JuneErrorBoundaryProps {
|
|
99
|
+
children?: ReactNode;
|
|
100
|
+
fallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
|
|
101
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
102
|
+
/** When any value changes, a caught error is cleared and children re-render. */
|
|
103
|
+
resetKeys?: readonly unknown[];
|
|
104
|
+
}
|
|
105
|
+
interface State {
|
|
106
|
+
error: Error | null;
|
|
107
|
+
}
|
|
108
|
+
declare class JuneErrorBoundary extends Component<JuneErrorBoundaryProps, State> {
|
|
109
|
+
state: State;
|
|
110
|
+
static getDerivedStateFromError(error: Error): State;
|
|
111
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
112
|
+
componentDidUpdate(prev: JuneErrorBoundaryProps): void;
|
|
113
|
+
reset: () => void;
|
|
114
|
+
render(): ReactNode;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type JuneRendererProps = Omit<OpenUIRendererProps, "library" | "response" | "isStreaming" | "onAction" | "onError" | "className" | "style"> & {
|
|
118
|
+
library: OpenUILibrary;
|
|
119
|
+
/** Accumulated model output. OpenUI does the incremental parsing. */
|
|
120
|
+
response: string | null;
|
|
121
|
+
isStreaming?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Render prose around OpenUI statements (default true). The response may be
|
|
124
|
+
* plain OpenUI Lang, or prose + OpenUI Lang, optionally inside ``` fences.
|
|
125
|
+
* Set false to hand the response to OpenUI untouched.
|
|
126
|
+
*/
|
|
127
|
+
mixedContent?: boolean;
|
|
128
|
+
/** Custom renderer for prose segments. Default: <p className="june-text">. */
|
|
129
|
+
renderText?: (text: string, index: number) => ReactNode;
|
|
130
|
+
theme?: JuneThemeMode;
|
|
131
|
+
themeVars?: JuneThemeVars;
|
|
132
|
+
className?: string;
|
|
133
|
+
style?: CSSProperties;
|
|
134
|
+
actions?: JuneActionMap;
|
|
135
|
+
confirmAction?: ConfirmAction;
|
|
136
|
+
parseActionEvent?: ActionEventParser;
|
|
137
|
+
/** Raw OpenUI action event (called for every action, before June actions). */
|
|
138
|
+
onAction?: (event: OpenUIActionEvent) => void;
|
|
139
|
+
/** Raw OpenUI errors (called with [] when they resolve). */
|
|
140
|
+
onError?: (errors: unknown[]) => void;
|
|
141
|
+
/** Structured errors: parse, render, and action failures. */
|
|
142
|
+
onJuneError?: (error: JuneError) => void;
|
|
143
|
+
loadingFallback?: ReactNode;
|
|
144
|
+
emptyFallback?: ReactNode;
|
|
145
|
+
errorFallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
|
|
146
|
+
resetKeys?: readonly unknown[];
|
|
147
|
+
};
|
|
148
|
+
declare function JuneRenderer(props: JuneRendererProps): react.JSX.Element;
|
|
149
|
+
|
|
150
|
+
declare function useResolvedTheme(mode: JuneThemeMode): JuneResolvedTheme;
|
|
151
|
+
interface JuneThemeProviderProps {
|
|
152
|
+
mode?: JuneThemeMode;
|
|
153
|
+
/** CSS variable overrides, e.g. { "--june-accent": "#0ea5e9" }. */
|
|
154
|
+
vars?: JuneThemeVars;
|
|
155
|
+
className?: string;
|
|
156
|
+
style?: CSSProperties;
|
|
157
|
+
children?: ReactNode;
|
|
158
|
+
}
|
|
159
|
+
declare function JuneThemeProvider({ mode, vars, className, style, children, }: JuneThemeProviderProps): react.JSX.Element;
|
|
160
|
+
|
|
161
|
+
declare const darkTheme: JuneThemeVars;
|
|
162
|
+
|
|
163
|
+
interface JuneContextValue {
|
|
164
|
+
mode: JuneThemeMode;
|
|
165
|
+
theme: JuneResolvedTheme;
|
|
166
|
+
}
|
|
167
|
+
declare function useJuneTheme(): JuneContextValue;
|
|
168
|
+
|
|
169
|
+
/** Re-export of OpenUI's component definer under a June name. */
|
|
170
|
+
declare const defineJuneComponent: typeof defineComponent;
|
|
171
|
+
type OpenUILibraryOptions = Parameters<typeof createLibrary>[0];
|
|
172
|
+
type JuneLibraryOptions = OpenUILibraryOptions & {
|
|
173
|
+
/** If set, only these component names are kept (allowlist). */
|
|
174
|
+
allow?: readonly string[];
|
|
175
|
+
/** Component names to remove (applied after allow). */
|
|
176
|
+
deny?: readonly string[];
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Thin wrapper over OpenUI's createLibrary that validates names and
|
|
180
|
+
* supports allow/deny lists. Create the library once at module scope so its
|
|
181
|
+
* reference stays stable.
|
|
182
|
+
*/
|
|
183
|
+
declare function createJuneLibrary(options: JuneLibraryOptions): ReturnType<typeof createLibrary>;
|
|
184
|
+
|
|
185
|
+
type StreamStatus = "idle" | "streaming" | "done" | "error" | "aborted";
|
|
186
|
+
type StreamChunk = string | Uint8Array;
|
|
187
|
+
type StreamSource = ReadableStream<Uint8Array> | ReadableStream<string> | AsyncIterable<StreamChunk>;
|
|
188
|
+
interface ConsumeStreamOptions {
|
|
189
|
+
signal?: AbortSignal;
|
|
190
|
+
/** Called per decoded chunk with the new text and the full text so far. */
|
|
191
|
+
onText?: (delta: string, accumulated: string) => void;
|
|
192
|
+
/** Resolve with "" instead of throwing STREAM_EMPTY. */
|
|
193
|
+
allowEmpty?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface SseOptions {
|
|
196
|
+
/** Map an SSE frame to text. Return null/"" to skip. Default: the raw data. */
|
|
197
|
+
extract?: (data: string, event: string) => string | null | undefined;
|
|
198
|
+
/** Frame data that ends the stream. Default "[DONE]". Use null to disable. */
|
|
199
|
+
doneSentinel?: string | null;
|
|
200
|
+
}
|
|
201
|
+
type FetchStreamOptions = RequestInit & {
|
|
202
|
+
sse?: boolean | SseOptions;
|
|
203
|
+
};
|
|
204
|
+
interface JuneStreamState {
|
|
205
|
+
response: string;
|
|
206
|
+
isStreaming: boolean;
|
|
207
|
+
status: StreamStatus;
|
|
208
|
+
error: JuneError | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type StreamStarter = StreamSource | ((signal: AbortSignal) => StreamSource | Promise<StreamSource>);
|
|
212
|
+
interface UseJuneStreamOptions {
|
|
213
|
+
allowEmpty?: boolean;
|
|
214
|
+
onError?: (error: JuneError) => void;
|
|
215
|
+
onComplete?: (text: string) => void;
|
|
216
|
+
}
|
|
217
|
+
interface UseJuneStreamResult extends JuneStreamState {
|
|
218
|
+
start: (source: StreamStarter) => Promise<string | null>;
|
|
219
|
+
startFetch: (input: RequestInfo | URL, options?: FetchStreamOptions) => Promise<string | null>;
|
|
220
|
+
abort: () => void;
|
|
221
|
+
reset: () => void;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Accumulates a stream into `response`, with state updates coalesced to
|
|
225
|
+
* roughly one per frame, abort support, and cleanup on unmount.
|
|
226
|
+
* Starting a new stream cancels the previous one.
|
|
227
|
+
*/
|
|
228
|
+
declare function useJuneStream(options?: UseJuneStreamOptions): UseJuneStreamResult;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Reads a stream to completion, decoding bytes safely (multi-byte characters
|
|
232
|
+
* split across chunks are handled) and accumulating text. Does not parse
|
|
233
|
+
* OpenUI Lang; parsing stays with OpenUI's Renderer.
|
|
234
|
+
*/
|
|
235
|
+
declare function consumeStream(source: StreamSource, options?: ConsumeStreamOptions): Promise<string>;
|
|
236
|
+
|
|
237
|
+
/** fetch() wrapper that returns a StreamSource, with structured errors. */
|
|
238
|
+
declare function fetchStream(input: RequestInfo | URL, options?: FetchStreamOptions): Promise<StreamSource>;
|
|
239
|
+
|
|
240
|
+
/** Converts a Server-Sent Events byte/text stream into an async iterable of text. */
|
|
241
|
+
declare function sseToText(source: StreamSource, options?: SseOptions & {
|
|
242
|
+
signal?: AbortSignal;
|
|
243
|
+
}): AsyncGenerator<string, void, undefined>;
|
|
244
|
+
/**
|
|
245
|
+
* Builds an `extract` function that reads a string at a dotted JSON path,
|
|
246
|
+
* e.g. jsonFieldExtractor("choices.0.delta.content").
|
|
247
|
+
*/
|
|
248
|
+
declare function jsonFieldExtractor(path: string): (data: string) => string | null;
|
|
249
|
+
|
|
250
|
+
type JuneUIProps = Omit<JuneRendererProps, "library"> & {
|
|
251
|
+
/** Defaults to OpenUI's built-in library (same behaviour as 0.1.0). */
|
|
252
|
+
library?: OpenUILibrary;
|
|
253
|
+
};
|
|
254
|
+
declare function JuneUI({ library, ...props }: JuneUIProps): react.JSX.Element;
|
|
255
|
+
|
|
256
|
+
export { type ActionEventParser, type ActionOutcome, type ConfirmAction, type ConsumeStreamOptions, type FallbackArgs, type FetchStreamOptions, type JuneAction, type JuneActionContext, type JuneActionDefinition, type JuneActionMap, JuneError, JuneErrorBoundary, type JuneErrorBoundaryProps, type JuneErrorCode, type JuneErrorOptions, type JuneLibraryOptions, JuneRenderer, type JuneRendererProps, type JuneResolvedTheme, type JuneStreamState, type JuneThemeMode, JuneThemeProvider, type JuneThemeProviderProps, type JuneThemeVars, JuneUI, type JuneUIProps, type OpenUIActionEvent, type OpenUILibrary, type OpenUIRendererProps, type ParsedActionEvent, type RunActionOptions, type SchemaLike, type SseOptions, type StreamChunk, type StreamSource, type StreamStarter, type StreamStatus, type UseJuneStreamOptions, type UseJuneStreamResult, consumeStream, createActionHandler, createJuneLibrary, darkTheme, defaultParseActionEvent, defineJuneAction, defineJuneComponent, fetchStream, isJuneError, jsonFieldExtractor, lightTheme, runAction, sseToText, toJuneError, useJuneStream, useJuneTheme, useResolvedTheme };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps, Component, ReactNode, ErrorInfo, CSSProperties } from 'react';
|
|
3
|
+
import { Renderer, createLibrary, defineComponent } from '@openuidev/react-lang';
|
|
4
|
+
|
|
5
|
+
type JuneErrorCode = "PARSE_ERROR" | "RENDER_ERROR" | "STREAM_ERROR" | "STREAM_ABORTED" | "STREAM_EMPTY" | "NETWORK_ERROR" | "ACTION_ERROR" | "ACTION_VALIDATION_ERROR" | "ACTION_REJECTED" | "LIBRARY_ERROR";
|
|
6
|
+
interface JuneErrorOptions {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
details?: unknown;
|
|
9
|
+
}
|
|
10
|
+
declare class JuneError extends Error {
|
|
11
|
+
readonly code: JuneErrorCode;
|
|
12
|
+
readonly details?: unknown;
|
|
13
|
+
constructor(code: JuneErrorCode, message: string, options?: JuneErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
declare function isJuneError(value: unknown): value is JuneError;
|
|
16
|
+
declare function toJuneError(error: unknown, fallbackCode: JuneErrorCode, message?: string): JuneError;
|
|
17
|
+
|
|
18
|
+
/** Props of OpenUI's real Renderer. Derived, never hand-copied. */
|
|
19
|
+
type OpenUIRendererProps = ComponentProps<typeof Renderer>;
|
|
20
|
+
/** The library type OpenUI's Renderer accepts. */
|
|
21
|
+
type OpenUILibrary = OpenUIRendererProps["library"];
|
|
22
|
+
/** The event OpenUI passes to onAction. */
|
|
23
|
+
type OpenUIActionEvent = Parameters<NonNullable<OpenUIRendererProps["onAction"]>>[0];
|
|
24
|
+
type JuneThemeMode = "light" | "dark" | "system";
|
|
25
|
+
type JuneResolvedTheme = "light" | "dark";
|
|
26
|
+
|
|
27
|
+
/** Anything with a zod-style safeParse. No hard dependency on zod. */
|
|
28
|
+
interface SchemaLike<T> {
|
|
29
|
+
safeParse(data: unknown): {
|
|
30
|
+
success: true;
|
|
31
|
+
data: T;
|
|
32
|
+
} | {
|
|
33
|
+
success: false;
|
|
34
|
+
error: unknown;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface JuneActionContext {
|
|
38
|
+
name: string;
|
|
39
|
+
/** The raw OpenUI action event. */
|
|
40
|
+
event: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface JuneActionDefinition<TPayload = unknown> {
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Validates the payload before the handler runs. */
|
|
45
|
+
schema?: SchemaLike<TPayload>;
|
|
46
|
+
/** Sensitive actions are denied unless a confirm handler approves them. */
|
|
47
|
+
sensitive?: boolean;
|
|
48
|
+
/** Per-action confirmation; overrides the global confirmAction. */
|
|
49
|
+
confirm?: (args: {
|
|
50
|
+
name: string;
|
|
51
|
+
payload: TPayload;
|
|
52
|
+
description?: string;
|
|
53
|
+
}) => boolean | Promise<boolean>;
|
|
54
|
+
handler: (payload: TPayload, context: JuneActionContext) => void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
type JuneAction<TPayload = unknown> = Readonly<JuneActionDefinition<TPayload>> & {
|
|
57
|
+
readonly __june: "action";
|
|
58
|
+
};
|
|
59
|
+
type JuneActionMap = Record<string, JuneAction<any>>;
|
|
60
|
+
declare function defineJuneAction<TPayload = unknown>(definition: JuneActionDefinition<TPayload>): JuneAction<TPayload>;
|
|
61
|
+
|
|
62
|
+
interface ParsedActionEvent {
|
|
63
|
+
name: string;
|
|
64
|
+
payload: unknown;
|
|
65
|
+
}
|
|
66
|
+
type ActionEventParser = (event: OpenUIActionEvent) => ParsedActionEvent | null;
|
|
67
|
+
type ConfirmAction = (args: {
|
|
68
|
+
name: string;
|
|
69
|
+
payload: unknown;
|
|
70
|
+
description?: string;
|
|
71
|
+
}) => boolean | Promise<boolean>;
|
|
72
|
+
type ActionOutcome = "handled" | "unhandled" | "rejected" | "failed";
|
|
73
|
+
/**
|
|
74
|
+
* BEST-EFFORT default: reads the action name from `type`/`name`/`action` and
|
|
75
|
+
* the payload from `params`/`payload`/`data`. Verify against OpenUI's actual
|
|
76
|
+
* action event type (see the .d.ts) and override with `parseActionEvent`
|
|
77
|
+
* if the shape differs. This is the only place that guesses the event shape.
|
|
78
|
+
*/
|
|
79
|
+
declare const defaultParseActionEvent: ActionEventParser;
|
|
80
|
+
interface RunActionOptions {
|
|
81
|
+
actions: JuneActionMap;
|
|
82
|
+
parseEvent?: ActionEventParser;
|
|
83
|
+
confirm?: ConfirmAction;
|
|
84
|
+
onError?: (error: JuneError) => void;
|
|
85
|
+
onUnhandled?: (event: OpenUIActionEvent) => void;
|
|
86
|
+
}
|
|
87
|
+
/** Looks up and runs a registered action. Never evaluates model-provided code. */
|
|
88
|
+
declare function runAction(event: OpenUIActionEvent, options: RunActionOptions): Promise<ActionOutcome>;
|
|
89
|
+
declare function createActionHandler(options: RunActionOptions): (event: OpenUIActionEvent) => void;
|
|
90
|
+
|
|
91
|
+
type JuneThemeVars = Record<string, string>;
|
|
92
|
+
declare const lightTheme: JuneThemeVars;
|
|
93
|
+
|
|
94
|
+
interface FallbackArgs {
|
|
95
|
+
error: Error;
|
|
96
|
+
reset: () => void;
|
|
97
|
+
}
|
|
98
|
+
interface JuneErrorBoundaryProps {
|
|
99
|
+
children?: ReactNode;
|
|
100
|
+
fallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
|
|
101
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
102
|
+
/** When any value changes, a caught error is cleared and children re-render. */
|
|
103
|
+
resetKeys?: readonly unknown[];
|
|
104
|
+
}
|
|
105
|
+
interface State {
|
|
106
|
+
error: Error | null;
|
|
107
|
+
}
|
|
108
|
+
declare class JuneErrorBoundary extends Component<JuneErrorBoundaryProps, State> {
|
|
109
|
+
state: State;
|
|
110
|
+
static getDerivedStateFromError(error: Error): State;
|
|
111
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
112
|
+
componentDidUpdate(prev: JuneErrorBoundaryProps): void;
|
|
113
|
+
reset: () => void;
|
|
114
|
+
render(): ReactNode;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type JuneRendererProps = Omit<OpenUIRendererProps, "library" | "response" | "isStreaming" | "onAction" | "onError" | "className" | "style"> & {
|
|
118
|
+
library: OpenUILibrary;
|
|
119
|
+
/** Accumulated model output. OpenUI does the incremental parsing. */
|
|
120
|
+
response: string | null;
|
|
121
|
+
isStreaming?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Render prose around OpenUI statements (default true). The response may be
|
|
124
|
+
* plain OpenUI Lang, or prose + OpenUI Lang, optionally inside ``` fences.
|
|
125
|
+
* Set false to hand the response to OpenUI untouched.
|
|
126
|
+
*/
|
|
127
|
+
mixedContent?: boolean;
|
|
128
|
+
/** Custom renderer for prose segments. Default: <p className="june-text">. */
|
|
129
|
+
renderText?: (text: string, index: number) => ReactNode;
|
|
130
|
+
theme?: JuneThemeMode;
|
|
131
|
+
themeVars?: JuneThemeVars;
|
|
132
|
+
className?: string;
|
|
133
|
+
style?: CSSProperties;
|
|
134
|
+
actions?: JuneActionMap;
|
|
135
|
+
confirmAction?: ConfirmAction;
|
|
136
|
+
parseActionEvent?: ActionEventParser;
|
|
137
|
+
/** Raw OpenUI action event (called for every action, before June actions). */
|
|
138
|
+
onAction?: (event: OpenUIActionEvent) => void;
|
|
139
|
+
/** Raw OpenUI errors (called with [] when they resolve). */
|
|
140
|
+
onError?: (errors: unknown[]) => void;
|
|
141
|
+
/** Structured errors: parse, render, and action failures. */
|
|
142
|
+
onJuneError?: (error: JuneError) => void;
|
|
143
|
+
loadingFallback?: ReactNode;
|
|
144
|
+
emptyFallback?: ReactNode;
|
|
145
|
+
errorFallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
|
|
146
|
+
resetKeys?: readonly unknown[];
|
|
147
|
+
};
|
|
148
|
+
declare function JuneRenderer(props: JuneRendererProps): react.JSX.Element;
|
|
149
|
+
|
|
150
|
+
declare function useResolvedTheme(mode: JuneThemeMode): JuneResolvedTheme;
|
|
151
|
+
interface JuneThemeProviderProps {
|
|
152
|
+
mode?: JuneThemeMode;
|
|
153
|
+
/** CSS variable overrides, e.g. { "--june-accent": "#0ea5e9" }. */
|
|
154
|
+
vars?: JuneThemeVars;
|
|
155
|
+
className?: string;
|
|
156
|
+
style?: CSSProperties;
|
|
157
|
+
children?: ReactNode;
|
|
158
|
+
}
|
|
159
|
+
declare function JuneThemeProvider({ mode, vars, className, style, children, }: JuneThemeProviderProps): react.JSX.Element;
|
|
160
|
+
|
|
161
|
+
declare const darkTheme: JuneThemeVars;
|
|
162
|
+
|
|
163
|
+
interface JuneContextValue {
|
|
164
|
+
mode: JuneThemeMode;
|
|
165
|
+
theme: JuneResolvedTheme;
|
|
166
|
+
}
|
|
167
|
+
declare function useJuneTheme(): JuneContextValue;
|
|
168
|
+
|
|
169
|
+
/** Re-export of OpenUI's component definer under a June name. */
|
|
170
|
+
declare const defineJuneComponent: typeof defineComponent;
|
|
171
|
+
type OpenUILibraryOptions = Parameters<typeof createLibrary>[0];
|
|
172
|
+
type JuneLibraryOptions = OpenUILibraryOptions & {
|
|
173
|
+
/** If set, only these component names are kept (allowlist). */
|
|
174
|
+
allow?: readonly string[];
|
|
175
|
+
/** Component names to remove (applied after allow). */
|
|
176
|
+
deny?: readonly string[];
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Thin wrapper over OpenUI's createLibrary that validates names and
|
|
180
|
+
* supports allow/deny lists. Create the library once at module scope so its
|
|
181
|
+
* reference stays stable.
|
|
182
|
+
*/
|
|
183
|
+
declare function createJuneLibrary(options: JuneLibraryOptions): ReturnType<typeof createLibrary>;
|
|
184
|
+
|
|
185
|
+
type StreamStatus = "idle" | "streaming" | "done" | "error" | "aborted";
|
|
186
|
+
type StreamChunk = string | Uint8Array;
|
|
187
|
+
type StreamSource = ReadableStream<Uint8Array> | ReadableStream<string> | AsyncIterable<StreamChunk>;
|
|
188
|
+
interface ConsumeStreamOptions {
|
|
189
|
+
signal?: AbortSignal;
|
|
190
|
+
/** Called per decoded chunk with the new text and the full text so far. */
|
|
191
|
+
onText?: (delta: string, accumulated: string) => void;
|
|
192
|
+
/** Resolve with "" instead of throwing STREAM_EMPTY. */
|
|
193
|
+
allowEmpty?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface SseOptions {
|
|
196
|
+
/** Map an SSE frame to text. Return null/"" to skip. Default: the raw data. */
|
|
197
|
+
extract?: (data: string, event: string) => string | null | undefined;
|
|
198
|
+
/** Frame data that ends the stream. Default "[DONE]". Use null to disable. */
|
|
199
|
+
doneSentinel?: string | null;
|
|
200
|
+
}
|
|
201
|
+
type FetchStreamOptions = RequestInit & {
|
|
202
|
+
sse?: boolean | SseOptions;
|
|
203
|
+
};
|
|
204
|
+
interface JuneStreamState {
|
|
205
|
+
response: string;
|
|
206
|
+
isStreaming: boolean;
|
|
207
|
+
status: StreamStatus;
|
|
208
|
+
error: JuneError | null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type StreamStarter = StreamSource | ((signal: AbortSignal) => StreamSource | Promise<StreamSource>);
|
|
212
|
+
interface UseJuneStreamOptions {
|
|
213
|
+
allowEmpty?: boolean;
|
|
214
|
+
onError?: (error: JuneError) => void;
|
|
215
|
+
onComplete?: (text: string) => void;
|
|
216
|
+
}
|
|
217
|
+
interface UseJuneStreamResult extends JuneStreamState {
|
|
218
|
+
start: (source: StreamStarter) => Promise<string | null>;
|
|
219
|
+
startFetch: (input: RequestInfo | URL, options?: FetchStreamOptions) => Promise<string | null>;
|
|
220
|
+
abort: () => void;
|
|
221
|
+
reset: () => void;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Accumulates a stream into `response`, with state updates coalesced to
|
|
225
|
+
* roughly one per frame, abort support, and cleanup on unmount.
|
|
226
|
+
* Starting a new stream cancels the previous one.
|
|
227
|
+
*/
|
|
228
|
+
declare function useJuneStream(options?: UseJuneStreamOptions): UseJuneStreamResult;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Reads a stream to completion, decoding bytes safely (multi-byte characters
|
|
232
|
+
* split across chunks are handled) and accumulating text. Does not parse
|
|
233
|
+
* OpenUI Lang; parsing stays with OpenUI's Renderer.
|
|
234
|
+
*/
|
|
235
|
+
declare function consumeStream(source: StreamSource, options?: ConsumeStreamOptions): Promise<string>;
|
|
236
|
+
|
|
237
|
+
/** fetch() wrapper that returns a StreamSource, with structured errors. */
|
|
238
|
+
declare function fetchStream(input: RequestInfo | URL, options?: FetchStreamOptions): Promise<StreamSource>;
|
|
239
|
+
|
|
240
|
+
/** Converts a Server-Sent Events byte/text stream into an async iterable of text. */
|
|
241
|
+
declare function sseToText(source: StreamSource, options?: SseOptions & {
|
|
242
|
+
signal?: AbortSignal;
|
|
243
|
+
}): AsyncGenerator<string, void, undefined>;
|
|
244
|
+
/**
|
|
245
|
+
* Builds an `extract` function that reads a string at a dotted JSON path,
|
|
246
|
+
* e.g. jsonFieldExtractor("choices.0.delta.content").
|
|
247
|
+
*/
|
|
248
|
+
declare function jsonFieldExtractor(path: string): (data: string) => string | null;
|
|
249
|
+
|
|
250
|
+
type JuneUIProps = Omit<JuneRendererProps, "library"> & {
|
|
251
|
+
/** Defaults to OpenUI's built-in library (same behaviour as 0.1.0). */
|
|
252
|
+
library?: OpenUILibrary;
|
|
253
|
+
};
|
|
254
|
+
declare function JuneUI({ library, ...props }: JuneUIProps): react.JSX.Element;
|
|
255
|
+
|
|
256
|
+
export { type ActionEventParser, type ActionOutcome, type ConfirmAction, type ConsumeStreamOptions, type FallbackArgs, type FetchStreamOptions, type JuneAction, type JuneActionContext, type JuneActionDefinition, type JuneActionMap, JuneError, JuneErrorBoundary, type JuneErrorBoundaryProps, type JuneErrorCode, type JuneErrorOptions, type JuneLibraryOptions, JuneRenderer, type JuneRendererProps, type JuneResolvedTheme, type JuneStreamState, type JuneThemeMode, JuneThemeProvider, type JuneThemeProviderProps, type JuneThemeVars, JuneUI, type JuneUIProps, type OpenUIActionEvent, type OpenUILibrary, type OpenUIRendererProps, type ParsedActionEvent, type RunActionOptions, type SchemaLike, type SseOptions, type StreamChunk, type StreamSource, type StreamStarter, type StreamStatus, type UseJuneStreamOptions, type UseJuneStreamResult, consumeStream, createActionHandler, createJuneLibrary, darkTheme, defaultParseActionEvent, defineJuneAction, defineJuneComponent, fetchStream, isJuneError, jsonFieldExtractor, lightTheme, runAction, sseToText, toJuneError, useJuneStream, useJuneTheme, useResolvedTheme };
|