@june-ai/june-ui 0.2.7 → 0.2.9

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/dist/index.d.ts CHANGED
@@ -1,548 +1,103 @@
1
+ import { JuneRendererProps, AnyComponentDefinition, OpenUILibrary, ComponentRegistry, RegisterOptions } from './entry-core.js';
2
+ export { ALL_EXPORT_FORMATS, ActionEventParser, ActionOutcome, ApprovalChoice, ComponentProps, ComponentRegistryOptions, ConfirmAction, ConsumeStreamOptions, DOCUMENT_COMPONENT_DESCRIPTION, DefineComponentOptions, DocJSON, DocNode, DocumentBridge, DocumentBridgeOptions, DocumentChange, DocumentConflict, DocumentEditor, DocumentEditorProps, DocumentExportEvent, DocumentExportFormat, DocumentExporter, DocumentInstructionOptions, DocumentProgramUpdate, DocumentRecord, DocumentSavePayload, DocumentSnapshot, DocumentStore, ExportContext, ExportResult, FallbackArgs, FetchStreamOptions, IncomingDocument, JuneAction, JuneActionContext, JuneActionDefinition, JuneActionMap, JuneComponent, JuneComponentMeta, JuneContextValue, JuneDocumentContext, JuneDocumentEditorComponent, JuneDocumentOptions, JuneError, JuneErrorBoundary, JuneErrorBoundaryProps, JuneErrorCode, JuneErrorOptions, JuneLibraryOptions, JuneRenderProps, JuneRenderer, JuneResolvedTheme, JuneRuntimeContext, JuneRuntimeValue, JuneStreamState, JuneThemeInput, JuneThemeMode, JuneThemeProvider, JuneThemeProviderProps, JuneThemeSet, JuneThemeToken, JuneThemeVars, LangGraphExtractorOptions, MarkdownText, MarkdownTextProps, MixedContent, MixedContentOptions, OpenUIActionEvent, OpenUIRendererProps, ParsedActionEvent, PendingUpdate, ReceiveOutcome, ResolveChoice, ResponseChangeInfo, RunActionOptions, SchemaLike, SplitOptions, SplitResponse, SseOptions, StreamChunk, StreamSource, StreamStarter, StreamStatus, TextFormat, ToolApproval, ToolApprovalDecision, ToolApprovalEntry, ToolApprovalInput, ToolApprovalLabels, ToolApprovalList, ToolApprovalListProps, ToolApprovalProps, ToolApprovalRequest, ToolApprovalStatus, UseJuneStreamOptions, UseJuneStreamResult, UseToolApprovalResult, consumeStream, copyDocumentToClipboard, createActionHandler, createComponentRegistry, createDocumentStore, createJuneLibrary, createLangGraphExtractor, createTheme, darkTheme, defaultParseActionEvent, defaultToolApprovalLabels, defineComponent, defineJuneAction, defineJuneComponent, documentPromptOptions, downloadResult, exportDocument, fetchStream, getDefaultDocumentStore, getDocumentEditorInstructions, getDocumentEditorRules, interruptToApprovalRequests, isDocumentEcho, isJuneComponent, isJuneError, isThemeSet, jsonFieldExtractor, langGraphStreamOptions, lightTheme, listDocumentExporters, mergeDocuments, messageContentToText, normalizeProgram, readDocumentFromProgram, readLangGraphInterrupts, registerDocumentExporter, rememberDocumentEcho, resolveMixedContent, resolveThemeVars, runAction, serializeDocumentsForAgent, splitResponse, sseToText, toAsyncIterable, toJuneError, updateDocumentInProgram, useDocumentBridge, useDocumentOptions, useJuneRuntime, useJuneStream, useJuneTheme, useRegistryLibrary, useResolvedTheme, useToolApproval, validateComponentDefinition, withDocumentEditor } from './entry-core.js';
1
3
  import * as react from 'react';
2
- import { ComponentProps, Component, ReactNode, ErrorInfo, CSSProperties } from 'react';
3
- import * as _openuidev_react_lang from '@openuidev/react-lang';
4
- import { Renderer, createLibrary, defineComponent, Library } from '@openuidev/react-lang';
5
- import * as _openuidev_lang_core from '@openuidev/lang-core';
6
- import { z } from 'zod/v4';
4
+ import { ReactNode } from 'react';
5
+ import { PromptOptions } from '@openuidev/react-lang';
6
+ import 'zod/v4';
7
+ import 'zod/v4/core';
8
+ import '@openuidev/lang-core';
7
9
 
8
- type JuneErrorCode = "PARSE_ERROR" | "RENDER_ERROR" | "STREAM_ERROR" | "STREAM_ABORTED" | "STREAM_EMPTY" | "NETWORK_ERROR" | "ACTION_ERROR" | "ACTION_VALIDATION_ERROR" | "ACTION_REJECTED" | "LIBRARY_ERROR" | "DOCUMENT_ERROR" | "EXPORT_ERROR";
9
- interface JuneErrorOptions {
10
- cause?: unknown;
11
- details?: unknown;
12
- }
13
- declare class JuneError extends Error {
14
- readonly code: JuneErrorCode;
15
- readonly details?: unknown;
16
- constructor(code: JuneErrorCode, message: string, options?: JuneErrorOptions);
17
- }
18
- declare function isJuneError(value: unknown): value is JuneError;
19
- declare function toJuneError(error: unknown, fallbackCode: JuneErrorCode, message?: string): JuneError;
20
-
21
- /** Props of OpenUI's real Renderer. Derived, never hand-copied. */
22
- type OpenUIRendererProps = ComponentProps<typeof Renderer>;
23
- /** The library type OpenUI's Renderer accepts. */
24
- type OpenUILibrary = OpenUIRendererProps["library"];
25
- /** The event OpenUI passes to onAction. */
26
- type OpenUIActionEvent = Parameters<NonNullable<OpenUIRendererProps["onAction"]>>[0];
27
- type JuneThemeMode = "light" | "dark" | "system";
28
- type JuneResolvedTheme = "light" | "dark";
29
-
30
- /** Anything with a zod-style safeParse. No hard dependency on zod. */
31
- interface SchemaLike<T> {
32
- safeParse(data: unknown): {
33
- success: true;
34
- data: T;
35
- } | {
36
- success: false;
37
- error: unknown;
38
- };
39
- }
40
- interface JuneActionContext {
41
- name: string;
42
- /** The raw OpenUI action event. */
43
- event: unknown;
44
- }
45
- interface JuneActionDefinition<TPayload = unknown> {
46
- description?: string;
47
- /** Validates the payload before the handler runs. */
48
- schema?: SchemaLike<TPayload>;
49
- /** Sensitive actions are denied unless a confirm handler approves them. */
50
- sensitive?: boolean;
51
- /** Per-action confirmation; overrides the global confirmAction. */
52
- confirm?: (args: {
53
- name: string;
54
- payload: TPayload;
55
- description?: string;
56
- }) => boolean | Promise<boolean>;
57
- handler: (payload: TPayload, context: JuneActionContext) => void | Promise<void>;
58
- }
59
- type JuneAction<TPayload = unknown> = Readonly<JuneActionDefinition<TPayload>> & {
60
- readonly __june: "action";
61
- };
62
- type JuneActionMap = Record<string, JuneAction<any>>;
63
- declare function defineJuneAction<TPayload = unknown>(definition: JuneActionDefinition<TPayload>): JuneAction<TPayload>;
64
-
65
- interface ParsedActionEvent {
66
- name: string;
67
- payload: unknown;
68
- }
69
- type ActionEventParser = (event: OpenUIActionEvent) => ParsedActionEvent | null;
70
- type ConfirmAction = (args: {
71
- name: string;
72
- payload: unknown;
73
- description?: string;
74
- }) => boolean | Promise<boolean>;
75
- type ActionOutcome = "handled" | "unhandled" | "rejected" | "failed";
76
10
  /**
77
- * BEST-EFFORT default: reads the action name from `type`/`name`/`action` and
78
- * the payload from `params`/`payload`/`data`. Verify against OpenUI's actual
79
- * action event type (see the .d.ts) and override with `parseActionEvent`
80
- * if the shape differs. This is the only place that guesses the event shape.
11
+ * Props that can be set once (on a `createJuneUI` instance or a `JuneUIProvider`) instead of on
12
+ * every `<JuneUI>`. Props passed to `<JuneUI>` itself always win.
81
13
  */
82
- declare const defaultParseActionEvent: ActionEventParser;
83
- interface RunActionOptions {
84
- actions: JuneActionMap;
85
- parseEvent?: ActionEventParser;
86
- confirm?: ConfirmAction;
87
- onError?: (error: JuneError) => void;
88
- onUnhandled?: (event: OpenUIActionEvent) => void;
89
- }
90
- /** Looks up and runs a registered action. Never evaluates model-provided code. */
91
- declare function runAction(event: OpenUIActionEvent, options: RunActionOptions): Promise<ActionOutcome>;
92
- declare function createActionHandler(options: RunActionOptions): (event: OpenUIActionEvent) => void;
93
-
94
- interface PendingUpdate {
95
- json: DocJSON;
96
- title: string;
97
- /** AI changes merged in, with the user's version kept where both changed the same blocks. */
98
- merged: DocJSON;
99
- conflicts: number;
100
- }
101
- interface DocumentRecord {
102
- id: string;
103
- title: string;
104
- documentType?: string;
105
- status?: string;
106
- /** What the user currently sees. */
107
- json: DocJSON;
108
- /** The last AI version that was accepted. Used as the merge base. */
109
- baseJson: DocJSON;
110
- baseTitle: string;
111
- lastIncomingKey: string;
112
- /** Increments whenever `json` changes. */
113
- revision: number;
114
- /** Which editor (or "external") produced the latest change. */
115
- origin: string;
116
- pending: PendingUpdate | null;
117
- updatedAt: number;
118
- }
119
- interface IncomingDocument {
120
- id: string;
121
- title: string;
122
- json: DocJSON;
123
- documentType?: string;
124
- status?: string;
14
+ type JuneUIDefaults = Partial<Pick<JuneRendererProps, "mixedContent" | "textFormat" | "renderText" | "repair" | "theme" | "themeVars" | "className" | "actions" | "confirmAction" | "parseActionEvent" | "onAction" | "onJuneError" | "documents" | "loadingFallback" | "emptyFallback" | "errorFallback" | "toolProvider">>;
15
+
16
+ interface CreateJuneUIOptions {
17
+ /** Your components, made with `defineComponent`. Names must be new. */
18
+ components?: readonly AnyComponentDefinition[];
19
+ /** Components that replace built-ins with the same name. */
20
+ overrides?: readonly AnyComponentDefinition[];
21
+ /** Built-in component names to remove. */
22
+ remove?: readonly string[];
23
+ /** Library to start from. Default: June's library (OpenUI components + DocumentEditor). */
24
+ baseLibrary?: OpenUILibrary;
25
+ /** Default props for every `<JuneUI>` that uses this instance. */
26
+ defaults?: JuneUIDefaults;
27
+ }
28
+ /** An isolated June setup: its own component registry and default props. */
29
+ interface JuneUIInstance {
30
+ readonly registry: ComponentRegistry;
31
+ /** The OpenUI library for the current components (stable until they change). */
32
+ readonly library: OpenUILibrary;
33
+ readonly defaults: JuneUIDefaults;
34
+ /** Adds components at runtime. Mounted `<JuneUI>`s re-render. */
35
+ register(components: AnyComponentDefinition | readonly AnyComponentDefinition[], options?: RegisterOptions): JuneUIInstance;
36
+ /** The model's system prompt for these components. Generate it on the server and send it to the model. */
37
+ prompt(options?: PromptOptions): string;
125
38
  }
126
- type ReceiveOutcome = "created" | "unchanged" | "applied" | "merged" | "conflict";
127
- type ResolveChoice = "merge" | "replace" | "keep";
128
- interface DocumentStore {
129
- get(id: string): DocumentRecord | undefined;
130
- list(): DocumentRecord[];
131
- subscribe(listener: () => void): () => void;
132
- /** An AI version arrived. Applies it, merges it with user edits, or records a conflict. */
133
- receive(incoming: IncomingDocument): ReceiveOutcome;
134
- /** Seed or replace a document, for example from your database. */
135
- hydrate(doc: IncomingDocument): void;
136
- edit(id: string, json: DocJSON, origin: string): void;
137
- setTitle(id: string, title: string): void;
138
- resolve(id: string, choice: ResolveChoice): void;
139
- remove(id: string): void;
140
- }
141
- declare function createDocumentStore(): DocumentStore;
142
39
  /**
143
- * Remembers content produced from the user's own edits (for example when JuneUI rewrites
144
- * the OpenUI program). When that content comes back through the DocumentEditor props it is
145
- * ignored instead of being treated as a new AI version.
40
+ * Creates a June instance. Call it once, at module scope.
41
+ *
42
+ * ```tsx
43
+ * const june = createJuneUI({ components: [CustomCard] });
44
+ * <JuneUI june={june} response={response} isStreaming={isStreaming} />
45
+ * ```
146
46
  */
147
- declare function rememberDocumentEcho(store: DocumentStore, id: string, content: string): void;
148
- declare function isDocumentEcho(store: DocumentStore, id: string, content: string): boolean;
149
- /** The shared in-memory store used when none is provided. Documents are keyed by documentId. */
150
- declare function getDefaultDocumentStore(): DocumentStore;
151
-
152
- /** Structural type of a Tiptap / ProseMirror JSON node. Dependency-free on purpose. */
153
- interface DocNode {
154
- type: string;
155
- attrs?: Record<string, unknown>;
156
- content?: DocNode[];
157
- marks?: {
158
- type: string;
159
- attrs?: Record<string, unknown>;
160
- }[];
161
- text?: string;
162
- }
163
- /** Canonical document format: a Tiptap JSON document. */
164
- interface DocJSON {
165
- type: "doc";
166
- content?: DocNode[];
167
- }
168
- type DocumentExportFormat = "html" | "markdown" | "txt" | "docx" | "pdf";
169
- declare const ALL_EXPORT_FORMATS: readonly DocumentExportFormat[];
170
- interface DocumentSnapshot {
171
- documentId: string;
172
- title: string;
173
- documentType?: string;
174
- status?: string;
175
- json: DocJSON;
176
- }
177
- interface DocumentChange extends DocumentSnapshot {
178
- /** user = typed in the editor, ai = new AI version applied, merge = AI merged with user edits, resolve = conflict resolved. */
179
- source: "user" | "ai" | "merge" | "resolve";
180
- }
181
- interface DocumentSavePayload extends DocumentSnapshot {
182
- html: string;
183
- markdown: string;
184
- }
185
- interface DocumentExportEvent {
186
- documentId: string;
187
- format: string;
188
- filename: string;
189
- mimeType: string;
190
- blob?: Blob;
191
- text?: string;
192
- /** True when the exporter delivered the file itself (for example the PDF print dialog). */
193
- handled?: boolean;
194
- }
195
- interface DocumentConflict {
196
- documentId: string;
197
- title: string;
198
- /** Number of regions that both the user and the assistant changed. */
199
- conflicts: number;
200
- }
201
- interface JuneDocumentOptions {
202
- /** Share one store across editors. Defaults to a global in-memory store, keyed by documentId. */
203
- store?: DocumentStore;
204
- /** Debounce for autosave in ms (default 1500). 0 or less disables autosave. */
205
- autosaveDelay?: number;
206
- onDocumentChange?: (change: DocumentChange) => void;
207
- /** Persist the document. Called by autosave, the Save button and Ctrl/Cmd+S. */
208
- onSave?: (payload: DocumentSavePayload) => void | Promise<void>;
209
- onExport?: (event: DocumentExportEvent) => void;
210
- onDocumentReady?: (snapshot: DocumentSnapshot) => void;
211
- onConflict?: (conflict: DocumentConflict) => void;
212
- onError?: (error: JuneError) => void;
213
- }
214
- interface DocumentEditorProps {
215
- documentId: string;
216
- title?: string;
217
- /** Markdown, a Tiptap JSON string, or a Tiptap JSON object. */
218
- content?: string | DocJSON;
219
- documentType?: string;
220
- /** Default "draft". Drafts show an "AI draft" badge. */
221
- status?: string;
222
- editable?: boolean;
223
- exportFormats?: string[];
224
- /** "auto" follows the June theme context. */
225
- theme?: "auto" | "light" | "dark";
226
- className?: string;
227
- /** Show the drafting placeholder instead of the editor (use while content is streaming). */
228
- generating?: boolean;
229
- /** Callbacks and store. Merged over the values provided through JuneUI's `documents` prop. */
230
- options?: JuneDocumentOptions;
231
- }
47
+ declare function createJuneUI(options?: CreateJuneUIOptions): JuneUIInstance;
232
48
 
233
- type JuneThemeVars = Record<string, string>;
234
- /** Colors only. June never sets fonts, radii or backgrounds. */
235
- declare const lightTheme: JuneThemeVars;
236
-
237
- interface FallbackArgs {
238
- error: Error;
239
- reset: () => void;
240
- }
241
- interface JuneErrorBoundaryProps {
242
- children?: ReactNode;
243
- fallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
244
- onError?: (error: Error, info: ErrorInfo) => void;
245
- /** When any value changes, a caught error is cleared and children re-render. */
246
- resetKeys?: readonly unknown[];
247
- }
248
- interface State {
249
- error: Error | null;
250
- }
251
- declare class JuneErrorBoundary extends Component<JuneErrorBoundaryProps, State> {
252
- state: State;
253
- static getDerivedStateFromError(error: Error): State;
254
- componentDidCatch(error: Error, info: ErrorInfo): void;
255
- componentDidUpdate(prev: JuneErrorBoundaryProps): void;
256
- reset: () => void;
257
- render(): ReactNode;
258
- }
259
-
260
- type JuneRendererProps = Omit<OpenUIRendererProps, "library" | "response" | "isStreaming" | "onAction" | "onError" | "className" | "style"> & {
261
- library: OpenUILibrary;
262
- /** Accumulated model output. OpenUI does the incremental parsing. */
263
- response: string | null;
264
- isStreaming?: boolean;
265
- /** Allow prose around OpenUI statements (default true). */
266
- mixedContent?: boolean;
267
- /** Custom renderer for prose segments. Default: <p className="june-text">. */
268
- renderText?: (text: string, index: number) => ReactNode;
269
- /**
270
- * Rewrite common model mistakes after streaming ends (default true):
271
- * Grid and shorthand Card calls, and charts or tables left off root.
272
- * Set false to hand the program to OpenUI unchanged.
273
- */
274
- repair?: boolean;
275
- /** Omit to inherit the host app's look. "light" | "dark" | "system" opt in to June's colors. */
276
- theme?: JuneThemeMode;
277
- themeVars?: JuneThemeVars;
278
- className?: string;
279
- style?: CSSProperties;
280
- actions?: JuneActionMap;
281
- confirmAction?: ConfirmAction;
282
- parseActionEvent?: ActionEventParser;
283
- /** Raw OpenUI action event (called for every action, before June actions). */
284
- onAction?: (event: OpenUIActionEvent) => void;
285
- /** Raw OpenUI errors (called with [] when they resolve). */
286
- onError?: (errors: unknown[]) => void;
287
- /** Structured errors: parse, render, action, document and export failures. */
288
- onJuneError?: (error: JuneError) => void;
289
- /** Document editor callbacks and store. Memoize this object. */
290
- documents?: JuneDocumentOptions;
49
+ type JuneUIProps = Omit<JuneRendererProps, "library"> & {
291
50
  /**
292
- * Called with an updated OpenUI program when the user edits a document (body or title).
293
- * The matching `DocumentEditor(id, title, content)` call is rewritten with the new title and
294
- * the body as Markdown; nothing else in the program changes. Store the value and pass it back
295
- * as `response` to keep your program (and any "OpenUI Lang" view) in sync with the editor.
51
+ * Component library. Takes precedence over `june`. Default: the `june` instance, then the
52
+ * nearest `JuneUIProvider`, then June's default registry (OpenUI components + DocumentEditor
53
+ * + anything added with `registerComponent`).
296
54
  */
297
- onResponseChange?: (response: string, change: ResponseChangeInfo) => void;
298
- /** Debounce for onResponseChange in ms (default 300). */
299
- responseChangeDelay?: number;
300
- loadingFallback?: ReactNode;
301
- emptyFallback?: ReactNode;
302
- errorFallback?: ReactNode | ((args: FallbackArgs) => ReactNode);
303
- resetKeys?: readonly unknown[];
55
+ library?: OpenUILibrary;
56
+ /** Instance from `createJuneUI`: its components and default props. */
57
+ june?: JuneUIInstance;
304
58
  };
305
- interface ResponseChangeInfo {
306
- documentId: string;
307
- title: string;
308
- /** The document body written into the program, as Markdown. */
309
- markdown: string;
310
- source: DocumentChange["source"];
311
- }
312
- declare function JuneRenderer(props: JuneRendererProps): react.JSX.Element;
313
-
314
- /**
315
- * Rewrites the arguments of a `DocumentEditor(documentId, title, content, ...)` call inside an
316
- * OpenUI Lang program, leaving every other character of the program untouched.
317
- */
318
- interface DocumentProgramUpdate {
319
- title?: string;
320
- /** New document body (Markdown or a Tiptap JSON string). */
321
- content?: string;
322
- }
323
- /**
324
- * Finds the DocumentEditor call whose first argument equals `documentId` and replaces its title
325
- * and/or content. Returns the new program, or null when no matching call was found.
326
- */
327
- declare function updateDocumentInProgram(program: string, documentId: string, update: DocumentProgramUpdate, componentName?: string): string | null;
328
- /** Reads the current title and content of a DocumentEditor call, or null. */
329
- declare function readDocumentFromProgram(program: string, documentId: string, componentName?: string): {
330
- title: string;
331
- content: string;
332
- } | null;
333
-
334
- declare function useResolvedTheme(mode: JuneThemeMode): JuneResolvedTheme;
335
- interface JuneThemeProviderProps {
336
- /**
337
- * Omit to inherit the host app's look: no colors, fonts or color-scheme are applied.
338
- * "light" | "dark" | "system" opt in to June's text colors.
339
- */
340
- mode?: JuneThemeMode;
341
- /** CSS variable overrides, e.g. { "--june-accent": "#0ea5e9" }. */
342
- vars?: JuneThemeVars;
343
- className?: string;
344
- style?: CSSProperties;
59
+ /** Renders a model response (Markdown/prose and OpenUI Lang) with June's component library. */
60
+ declare function JuneUI({ library, june, ...props }: JuneUIProps): react.JSX.Element;
61
+
62
+ interface JuneUIContextValue {
63
+ june?: JuneUIInstance;
64
+ defaults?: JuneUIDefaults;
65
+ }
66
+ interface JuneUIProviderProps {
67
+ /** Instance from `createJuneUI`. Every `<JuneUI>` below uses its components and defaults. */
68
+ june?: JuneUIInstance;
69
+ /** Extra default props, applied over the instance's defaults. Memoize this object. */
70
+ defaults?: JuneUIDefaults;
345
71
  children?: ReactNode;
346
72
  }
347
- declare function JuneThemeProvider({ mode, vars, className, style, children, }: JuneThemeProviderProps): react.JSX.Element;
348
-
349
- declare const darkTheme: JuneThemeVars;
350
-
351
- interface JuneContextValue {
352
- mode: JuneThemeMode;
353
- theme: JuneResolvedTheme;
354
- }
355
- declare function useJuneTheme(): JuneContextValue;
356
- interface JuneRuntimeValue {
357
- /** True while the response is still streaming. Custom components use it to defer heavy work. */
358
- isStreaming: boolean;
359
- }
360
- declare const JuneRuntimeContext: react.Context<JuneRuntimeValue>;
361
- declare function useJuneRuntime(): JuneRuntimeValue;
362
-
363
- /** Re-export of OpenUI's component definer under a June name. */
364
- declare const defineJuneComponent: typeof defineComponent;
365
- type OpenUILibraryOptions = Parameters<typeof createLibrary>[0];
366
- type JuneLibraryOptions = OpenUILibraryOptions & {
367
- /** If set, only these component names are kept (allowlist). */
368
- allow?: readonly string[];
369
- /** Component names to remove (applied after allow). */
370
- deny?: readonly string[];
371
- };
372
- /**
373
- * Thin wrapper over OpenUI's createLibrary that validates names and
374
- * supports allow/deny lists. Create the library once at module scope so its
375
- * reference stays stable.
376
- */
377
- declare function createJuneLibrary(options: JuneLibraryOptions): ReturnType<typeof createLibrary>;
378
-
379
- type StreamStatus = "idle" | "streaming" | "done" | "error" | "aborted";
380
- type StreamChunk = string | Uint8Array;
381
- type StreamSource = ReadableStream<Uint8Array> | ReadableStream<string> | AsyncIterable<StreamChunk>;
382
- interface ConsumeStreamOptions {
383
- signal?: AbortSignal;
384
- /** Called per decoded chunk with the new text and the full text so far. */
385
- onText?: (delta: string, accumulated: string) => void;
386
- /** Resolve with "" instead of throwing STREAM_EMPTY. */
387
- allowEmpty?: boolean;
388
- }
389
- interface SseOptions {
390
- /** Map an SSE frame to text. Return null/"" to skip. Default: the raw data. */
391
- extract?: (data: string, event: string) => string | null | undefined;
392
- /** Frame data that ends the stream. Default "[DONE]". Use null to disable. */
393
- doneSentinel?: string | null;
394
- }
395
- type FetchStreamOptions = RequestInit & {
396
- sse?: boolean | SseOptions;
397
- };
398
- interface JuneStreamState {
399
- response: string;
400
- isStreaming: boolean;
401
- status: StreamStatus;
402
- error: JuneError | null;
403
- }
404
-
405
- type StreamStarter = StreamSource | ((signal: AbortSignal) => StreamSource | Promise<StreamSource>);
406
- interface UseJuneStreamOptions {
407
- allowEmpty?: boolean;
408
- onError?: (error: JuneError) => void;
409
- onComplete?: (text: string) => void;
410
- }
411
- interface UseJuneStreamResult extends JuneStreamState {
412
- start: (source: StreamStarter) => Promise<string | null>;
413
- startFetch: (input: RequestInfo | URL, options?: FetchStreamOptions) => Promise<string | null>;
414
- abort: () => void;
415
- reset: () => void;
416
- }
417
73
  /**
418
- * Accumulates a stream into `response`, with state updates coalesced to
419
- * roughly one per frame, abort support, and cleanup on unmount.
420
- * Starting a new stream cancels the previous one.
74
+ * Shares one June setup with every `<JuneUI>` below it — useful for a chat that renders a
75
+ * `<JuneUI>` per message. Props passed to a `<JuneUI>` still win.
421
76
  */
422
- declare function useJuneStream(options?: UseJuneStreamOptions): UseJuneStreamResult;
77
+ declare function JuneUIProvider({ june, defaults, children }: JuneUIProviderProps): react.JSX.Element;
78
+ /** The nearest `JuneUIProvider`'s value, or null. */
79
+ declare function useJuneUIContext(): JuneUIContextValue | null;
423
80
 
424
81
  /**
425
- * Reads a stream to completion, decoding bytes safely (multi-byte characters
426
- * split across chunks are handled) and accumulating text. Does not parse
427
- * OpenUI Lang; parsing stays with OpenUI's Renderer.
82
+ * June's default library: the OpenUI chat library, plus Stack, Modal and DocumentEditor.
83
+ * Root is Card, matching the chat language. Created once so its reference stays stable.
428
84
  */
429
- declare function consumeStream(source: StreamSource, options?: ConsumeStreamOptions): Promise<string>;
430
-
431
- /** fetch() wrapper that returns a StreamSource, with structured errors. */
432
- declare function fetchStream(input: RequestInfo | URL, options?: FetchStreamOptions): Promise<StreamSource>;
433
-
434
- /** Converts a Server-Sent Events byte/text stream into an async iterable of text. */
435
- declare function sseToText(source: StreamSource, options?: SseOptions & {
436
- signal?: AbortSignal;
437
- }): AsyncGenerator<string, void, undefined>;
85
+ declare const juneLibrary: OpenUILibrary;
438
86
  /**
439
- * Builds an `extract` function that reads a string at a dotted JSON path,
440
- * e.g. jsonFieldExtractor("choices.0.delta.content").
87
+ * The registry `<JuneUI>` renders with when it gets no `library` or `june` instance.
88
+ * `registerComponent` adds to it, so registered components appear in every default `<JuneUI>`.
441
89
  */
442
- declare function jsonFieldExtractor(path: string): (data: string) => string | null;
443
-
444
- /** Standalone editor. While a June response is still streaming, shows a placeholder instead of mounting Tiptap. */
445
- declare function DocumentEditor(props: DocumentEditorProps): react.JSX.Element;
446
- declare const JuneDocumentEditorComponent: _openuidev_react_lang.DefinedComponent<z.ZodObject<{
447
- documentId: z.ZodString;
448
- title: z.ZodString;
449
- content: z.ZodString;
450
- documentType: z.ZodOptional<z.ZodString>;
451
- status: z.ZodOptional<z.ZodString>;
452
- editable: z.ZodOptional<z.ZodBoolean>;
453
- exportFormats: z.ZodOptional<z.ZodArray<z.ZodString>>;
454
- }, z.core.$strip>>;
455
- type Extendable = Library & {
456
- extend: NonNullable<Library["extend"]>;
457
- };
458
- /**
459
- * Returns a library that contains every component of `library` plus DocumentEditor.
460
- * On Zod 4.1+ it also joins Card's children. Zod 3.25 (what the app bundles) has no
461
- * `util.mergeDefs`, and OpenUI's slot clone calls that, so the slot step is skipped
462
- * there. The component is still registered and can be rendered.
463
- */
464
- declare function withDocumentEditor(library: Extendable): Required<_openuidev_lang_core.Library<_openuidev_react_lang.ComponentRenderer<any>, _openuidev_lang_core.DefinedAction<any, string>>>;
465
-
466
- declare const JuneDocumentContext: react.Context<JuneDocumentOptions>;
467
- declare function useDocumentOptions(): JuneDocumentOptions;
468
-
469
- declare function mergeDocuments(base: DocJSON, local: DocJSON, incoming: DocJSON): {
470
- doc: DocJSON;
471
- conflicts: number;
472
- };
473
-
474
- interface ExportContext {
475
- documentId: string;
476
- title: string;
477
- json: DocJSON;
478
- /** File name without extension. */
479
- basename: string;
480
- }
481
- interface ExportResult {
482
- filename: string;
483
- mimeType: string;
484
- blob?: Blob;
485
- text?: string;
486
- /** True when the exporter delivered the file itself, for example the print dialog for PDF. */
487
- handled?: boolean;
488
- }
489
- type DocumentExporter = (context: ExportContext) => ExportResult | Promise<ExportResult>;
490
- /** Adds or replaces an export format. */
491
- declare function registerDocumentExporter(format: string, exporter: DocumentExporter): void;
492
- declare function listDocumentExporters(): string[];
493
- declare function exportDocument(format: string, doc: {
494
- documentId: string;
495
- title: string;
496
- json: DocJSON;
497
- }): Promise<ExportResult>;
498
- /** Starts a browser download for results that carry a Blob. */
499
- declare function downloadResult(result: ExportResult): void;
500
- /** Copies rich text and plain text. Returns false if the browser refuses. */
501
- declare function copyDocumentToClipboard(doc: {
502
- title: string;
503
- json: DocJSON;
504
- }): Promise<boolean>;
505
-
506
- interface DocumentInstructionOptions {
507
- /** Examples of document types for your product. Default covers common business documents. */
508
- documentTypes?: string[];
509
- /** Extra rules appended after the built-in ones (tone, legal disclaimers, language, ...). */
510
- extraRules?: string[];
511
- /** Name of the component in your library. Default "DocumentEditor". */
512
- componentName?: string;
513
- }
514
- /** Rules for the model. Pass them through your backend to any agent. */
515
- declare function getDocumentEditorRules(options?: DocumentInstructionOptions): string[];
516
- /** Text block you can paste into any agent's system prompt. */
517
- declare function getDocumentEditorInstructions(options?: DocumentInstructionOptions): string;
518
- /**
519
- * Options for OpenUI's `library.prompt(options)`. Merge these with your own PromptOptions.
520
- * Example: library.prompt({ ...documentPromptOptions(), preamble: "..." })
521
- */
522
- declare function documentPromptOptions(options?: DocumentInstructionOptions): {
523
- additionalRules: string[];
524
- examples: string[];
525
- };
526
-
527
- /**
528
- * Serialises the documents the user currently has (including their edits) as Markdown,
529
- * ready to attach to the next message so the agent can edit the right text.
530
- */
531
- declare function serializeDocumentsForAgent(options?: {
532
- store?: DocumentStore;
533
- ids?: string[];
534
- }): Promise<string>;
535
-
536
- type JuneUIProps = Omit<JuneRendererProps, "library"> & {
537
- /** Defaults to June's library: OpenUI's components plus DocumentEditor. */
538
- library?: OpenUILibrary;
539
- };
540
- declare function JuneUI({ library, ...props }: JuneUIProps): react.JSX.Element;
541
-
90
+ declare const defaultRegistry: ComponentRegistry;
542
91
  /**
543
- * June's default library: every OpenUI component plus DocumentEditor.
544
- * Created once so its reference stays stable.
92
+ * Adds components to the default registry used by `<JuneUI>`. Call once at startup, at module scope.
93
+ * Throws `JuneError("LIBRARY_ERROR")` when a name is taken, unless `override` is true.
94
+ *
95
+ * For isolated setups (several libraries, tests, micro-frontends) prefer `createJuneUI`.
545
96
  */
546
- declare const juneLibrary: Required<_openuidev_lang_core.Library<_openuidev_react_lang.ComponentRenderer<any>, _openuidev_lang_core.DefinedAction<any, string>>>;
97
+ declare function registerComponent(components: AnyComponentDefinition | readonly AnyComponentDefinition[], options?: {
98
+ override?: boolean;
99
+ }): ComponentRegistry;
100
+ /** Removes a component from the default registry (see `ComponentRegistry.unregister`). */
101
+ declare function unregisterComponent(name: string): ComponentRegistry;
547
102
 
548
- export { ALL_EXPORT_FORMATS, type ActionEventParser, type ActionOutcome, type ConfirmAction, type ConsumeStreamOptions, type DocJSON, type DocNode, type DocumentChange, type DocumentConflict, DocumentEditor, type DocumentEditorProps, type DocumentExportEvent, type DocumentExportFormat, type DocumentExporter, type DocumentInstructionOptions, type DocumentProgramUpdate, type DocumentRecord, type DocumentSavePayload, type DocumentSnapshot, type DocumentStore, type ExportContext, type ExportResult, type FallbackArgs, type FetchStreamOptions, type JuneAction, type JuneActionContext, type JuneActionDefinition, type JuneActionMap, JuneDocumentContext, JuneDocumentEditorComponent, type JuneDocumentOptions, JuneError, JuneErrorBoundary, type JuneErrorBoundaryProps, type JuneErrorCode, type JuneErrorOptions, type JuneLibraryOptions, JuneRenderer, type JuneRendererProps, type JuneResolvedTheme, JuneRuntimeContext, type JuneStreamState, type JuneThemeMode, JuneThemeProvider, type JuneThemeProviderProps, type JuneThemeVars, JuneUI, type JuneUIProps, type OpenUIActionEvent, type OpenUILibrary, type OpenUIRendererProps, type ParsedActionEvent, type ResponseChangeInfo, type RunActionOptions, type SchemaLike, type SseOptions, type StreamChunk, type StreamSource, type StreamStarter, type StreamStatus, type UseJuneStreamOptions, type UseJuneStreamResult, consumeStream, copyDocumentToClipboard, createActionHandler, createDocumentStore, createJuneLibrary, darkTheme, defaultParseActionEvent, defineJuneAction, defineJuneComponent, documentPromptOptions, downloadResult, exportDocument, fetchStream, getDefaultDocumentStore, getDocumentEditorInstructions, getDocumentEditorRules, isDocumentEcho, isJuneError, jsonFieldExtractor, juneLibrary, lightTheme, listDocumentExporters, mergeDocuments, readDocumentFromProgram, registerDocumentExporter, rememberDocumentEcho, runAction, serializeDocumentsForAgent, sseToText, toJuneError, updateDocumentInProgram, useDocumentOptions, useJuneRuntime, useJuneStream, useJuneTheme, useResolvedTheme, withDocumentEditor };
103
+ export { AnyComponentDefinition, ComponentRegistry, type CreateJuneUIOptions, JuneRendererProps, JuneUI, type JuneUIContextValue, type JuneUIDefaults, type JuneUIInstance, type JuneUIProps, JuneUIProvider, type JuneUIProviderProps, OpenUILibrary, RegisterOptions, createJuneUI, defaultRegistry, juneLibrary, registerComponent, unregisterComponent, useJuneUIContext };