@duskmoon-dev/components 0.5.7 → 0.6.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.
Files changed (42) hide show
  1. package/README.md +111 -4
  2. package/dist/chunk-kg46s2vk.js +238 -0
  3. package/dist/chunk-rd10x4gc.js +733 -0
  4. package/dist/components/chat/Chat.types.d.ts +15 -0
  5. package/dist/components/chat/ChatAuthoritativeQueue.d.ts +4 -0
  6. package/dist/components/chat/ChatSessionComposer.d.ts +4 -0
  7. package/dist/components/chat/ChatSessionComposer.types.d.ts +46 -0
  8. package/dist/components/chat/ComposerAttachment.types.d.ts +80 -0
  9. package/dist/components/chat/ComposerDraft.types.d.ts +89 -0
  10. package/dist/components/chat/ComposerProvider.types.d.ts +70 -0
  11. package/dist/components/chat/ComposerQueue.types.d.ts +64 -0
  12. package/dist/components/chat/ComposerSession.types.d.ts +78 -0
  13. package/dist/components/chat/ComposerSettings.d.ts +4 -0
  14. package/dist/components/chat/composer/CompletionList.d.ts +15 -0
  15. package/dist/components/chat/composer/ComposerShell.d.ts +23 -4
  16. package/dist/components/chat/composer/DraftLifecycle.d.ts +19 -0
  17. package/dist/components/chat/composer/EditorAdapter.types.d.ts +36 -0
  18. package/dist/components/chat/composer/PlainEditor.d.ts +2 -0
  19. package/dist/components/chat/composer/PlainSemanticEditor.d.ts +6 -0
  20. package/dist/components/chat/composer/PreservedDraft.d.ts +7 -0
  21. package/dist/components/chat/composer/SemanticComposer.d.ts +10 -0
  22. package/dist/components/chat/composer/attachments.d.ts +4 -0
  23. package/dist/components/chat/composer/document.d.ts +3 -1
  24. package/dist/components/chat/composer/drafts.d.ts +2 -0
  25. package/dist/components/chat/composer/providers.d.ts +40 -0
  26. package/dist/components/chat/composer/session.d.ts +30 -0
  27. package/dist/components/chat/composer/useComposerAttachments.d.ts +3 -0
  28. package/dist/components/chat/composer/useComposerDraft.d.ts +3 -0
  29. package/dist/components/chat/composer/useComposerProviders.d.ts +7 -0
  30. package/dist/components/chat/composer/useComposerSession.d.ts +16 -0
  31. package/dist/components/chat/index.d.ts +17 -0
  32. package/dist/components/chat/index.js +4765 -1286
  33. package/dist/components/chat/rich/LexicalEditor.d.ts +10 -0
  34. package/dist/components/chat/rich/RichChatComposer.d.ts +4 -0
  35. package/dist/components/chat/rich/index.d.ts +2 -0
  36. package/dist/components/chat/rich/index.js +3478 -0
  37. package/dist/components/chat/rich/nodes.d.ts +49 -0
  38. package/dist/generated/version.d.ts +1 -1
  39. package/dist/index.js +11994 -8740
  40. package/dist/infrastructure.js +1 -1
  41. package/dist/styles.css +180 -2
  42. package/package.json +27 -6
@@ -1,6 +1,7 @@
1
1
  import type { ComponentProps, ForwardRefExoticComponent, RefAttributes, ReactNode } from "react";
2
2
  import type { TextAreaProps } from "../input";
3
3
  import type { ComposerScope } from "./Composer.types";
4
+ import type { ComposerAttachmentIntakePolicy, ComposerAttachmentRejection } from "./ComposerAttachment.types";
4
5
  export type ChatPlacement = "start" | "end";
5
6
  export type ChatTimeline = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24;
6
7
  export type ChatBubbleColor = "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error";
@@ -76,6 +77,9 @@ export interface ChatQueueProps extends Omit<ComponentProps<"section">, "childre
76
77
  /** The application owns pending state and removes messages after acknowledgment. */
77
78
  pendingIds?: readonly string[];
78
79
  steerDisabled?: boolean;
80
+ /** Optional authoritative controls; legacy Steer/Remove remain the default. */
81
+ renderItemActions?: (item: ChatQueueItem, index: number, pending: boolean) => ReactNode;
82
+ renderItemContent?: (item: ChatQueueItem, index: number) => ReactNode;
79
83
  onSteer: (id: string) => void;
80
84
  onRemove: (id: string) => void;
81
85
  /** Accessible queue name. @default "Waiting messages" */
@@ -99,8 +103,12 @@ export interface ChatComposerSubmission {
99
103
  export interface ChatComposerCompletion {
100
104
  id: string;
101
105
  label: string;
106
+ /** Optional presentation; never part of the submitted document. */
107
+ icon?: ReactNode;
108
+ sourceLabel?: string;
102
109
  description?: ReactNode;
103
110
  disabled?: boolean;
111
+ group?: string;
104
112
  }
105
113
  export interface ChatComposerCompletionContext {
106
114
  value: string;
@@ -136,10 +144,17 @@ export interface ChatComposerProps extends Omit<ComponentProps<"div">, "children
136
144
  /** Enables the native file picker and attachment removal controls. */
137
145
  onAttachmentsChange?: (files: File[]) => void;
138
146
  accept?: string;
147
+ /** Shared validation for picker, pasted files, and dropped files. */
148
+ attachmentPolicy?: ComposerAttachmentIntakePolicy;
149
+ onAttachmentRejected?: (rejected: readonly ComposerAttachmentRejection[]) => void;
139
150
  /** @default true */
140
151
  multiple?: boolean;
141
152
  /** Permit a draft containing only files. @default false */
142
153
  allowAttachmentOnly?: boolean;
154
+ /** Compact Add menu, one send/stop action and ready-image strip. @default false */
155
+ compact?: boolean;
156
+ /** Additional actions in the compact Add menu. */
157
+ addMenu?: ReactNode;
143
158
  disabled?: boolean;
144
159
  /** Gates submission while keeping the draft editable. */
145
160
  busy?: boolean;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { ChatAuthoritativeQueueProps } from "./ComposerQueue.types";
3
+ /** Controlled queue projection: a request never changes confirmed membership. */
4
+ export declare function ChatAuthoritativeQueue(props: ChatAuthoritativeQueueProps): React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { ChatSessionComposerProps } from "./ChatSessionComposer.types";
3
+ /** Native textarea sessions with typed admission/recovery; legacy Chat.Composer remains compatible. */
4
+ export declare const ChatSessionComposer: React.ForwardRefExoticComponent<ChatSessionComposerProps & React.RefAttributes<import("./composer/EditorAdapter.types").ComposerEditorHandle>>;
@@ -0,0 +1,46 @@
1
+ import type { ComponentProps, ReactNode } from "react";
2
+ import type { ComposerDocumentUpdate, ComposerJson, ComposerScope } from "./Composer.types";
3
+ import type { ComposerAttachmentOptions } from "./ComposerAttachment.types";
4
+ import type { ComposerDraftAdapter } from "./ComposerDraft.types";
5
+ import type { ComposerCompletionProvider, ComposerProviderSelectionEffect } from "./ComposerProvider.types";
6
+ import type { ComposerActionPolicy, ComposerRuntimeState, ComposerSessionHost } from "./ComposerSession.types";
7
+ import type { ComposerEditorHandle } from "./composer/EditorAdapter.types";
8
+ /** Shared semantic session API; /chat/rich selects the optional editor adapter. */
9
+ export interface ChatSessionComposerProps extends Omit<ComponentProps<"div">, "children" | "onChange" | "onSubmit" | "ref"> {
10
+ readonly value: ComposerDocumentUpdate;
11
+ readonly onDocumentChange: (update: ComposerDocumentUpdate) => void;
12
+ readonly scope: ComposerScope;
13
+ readonly draftKey: string;
14
+ readonly host: ComposerSessionHost;
15
+ readonly runtime?: ComposerRuntimeState;
16
+ readonly policy?: ComposerActionPolicy;
17
+ /** Captured immutably with each logical submission. Interpretation is host-owned. */
18
+ readonly options?: Readonly<Record<string, ComposerJson>>;
19
+ /** Optional scoped storage. Loading is automatic; the user explicitly saves. */
20
+ readonly draftAdapter?: ComposerDraftAdapter;
21
+ readonly attachmentOptions?: Omit<ComposerAttachmentOptions, "scope">;
22
+ readonly providers?: readonly ComposerCompletionProvider[];
23
+ /** Invocation is a host action, independent of any prompt admission. */
24
+ readonly onProviderInvoke?: (effect: ComposerProviderSelectionEffect) => void | Promise<void>;
25
+ readonly disabled?: boolean;
26
+ readonly busy?: boolean;
27
+ readonly canSubmit?: boolean;
28
+ readonly allowAttachmentOnly?: boolean;
29
+ /** Compact Add menu, one send/stop action and ready-image strip. @default false */
30
+ readonly compact?: boolean;
31
+ /** Additional actions in the compact Add menu. */
32
+ readonly addMenu?: ReactNode;
33
+ readonly onStop?: () => void;
34
+ readonly label?: string;
35
+ readonly attachLabel?: string;
36
+ readonly stopLabel?: string;
37
+ readonly minRows?: number;
38
+ readonly maxRows?: number;
39
+ readonly error?: ReactNode;
40
+ readonly children?: ReactNode;
41
+ }
42
+ /** The rich and semantic plain adapters expose the same editor-independent API. */
43
+ export type ChatSessionComposerHandle = ComposerEditorHandle;
44
+ /** Final R0 public name: RichChatComposer, exported only at /chat/rich. */
45
+ export type RichChatComposerProps = ChatSessionComposerProps;
46
+ export type RichChatComposerHandle = ChatSessionComposerHandle;
@@ -0,0 +1,80 @@
1
+ import type { ComposerAttachmentEntry, ComposerAttachmentHandle, ComposerAttachmentMetadata, ComposerDraftAttachment, ComposerError, ComposerScope, ComposerSendableAttachment } from "./Composer.types";
2
+ export type ComposerAttachmentSource = "picker" | "paste" | "drop";
3
+ /** The same policy is applied to every intake path; it never consumes paste text. */
4
+ export interface ComposerAttachmentIntakePolicy {
5
+ /** Native accept syntax: comma-separated MIME types, wildcards or extensions. */
6
+ readonly accept?: string;
7
+ readonly maxFiles?: number;
8
+ readonly maxFileBytes?: number;
9
+ readonly validate?: (file: File, source: ComposerAttachmentSource) => ComposerError | undefined;
10
+ }
11
+ export interface ComposerAttachmentRejection {
12
+ readonly source: ComposerAttachmentSource;
13
+ readonly metadata: ComposerAttachmentMetadata;
14
+ readonly error: ComposerError;
15
+ }
16
+ /** Runtime intake result. Only the accepted list contains local File handles. */
17
+ export interface ComposerAttachmentIntakeResult {
18
+ readonly accepted: readonly File[];
19
+ readonly rejected: readonly ComposerAttachmentRejection[];
20
+ }
21
+ export interface ComposerAttachmentPreparationContext {
22
+ readonly entryId: string;
23
+ readonly scope: ComposerScope;
24
+ readonly signal: AbortSignal;
25
+ /** Reports upload progress from 0 to 1; obsolete calls are ignored. */
26
+ readonly reportProgress: (progress: number) => void;
27
+ }
28
+ export interface ComposerAttachmentOptions {
29
+ readonly scope: ComposerScope;
30
+ /** Optional draft ownership within a scope; changing it releases local files. */
31
+ readonly draftKey?: string;
32
+ readonly policy?: ComposerAttachmentIntakePolicy;
33
+ /** Hosts validate/prepare/upload and issue a portable sendable handle. */
34
+ readonly prepare: (file: File, context: ComposerAttachmentPreparationContext) => ComposerAttachmentHandle | Promise<ComposerAttachmentHandle>;
35
+ /**
36
+ * Explicit host policy for handles usable after draft recovery. Without this,
37
+ * every saved/restored occurrence requires reattachment. This is not server
38
+ * authorization or a guarantee that a later submission will be admitted.
39
+ */
40
+ readonly canRecover?: (attachment: ComposerSendableAttachment, scope: ComposerScope) => boolean;
41
+ }
42
+ export interface ComposerAttachmentSnapshot {
43
+ readonly scope: ComposerScope;
44
+ readonly draftKey?: string;
45
+ readonly generation: number;
46
+ readonly entries: readonly ComposerAttachmentEntry[];
47
+ /** Rejections stay visible until explicitly dismissed or the scope changes. */
48
+ readonly rejections: readonly ComposerAttachmentRejection[];
49
+ }
50
+ export interface ComposerAttachmentAdmission {
51
+ readonly entryIds: readonly string[];
52
+ readonly rejected: readonly ComposerAttachmentRejection[];
53
+ }
54
+ /** One owner and scope at a time. Runtime files/preview URLs never enter drafts. */
55
+ export interface ComposerAttachmentController {
56
+ readonly getSnapshot: () => ComposerAttachmentSnapshot;
57
+ readonly subscribe: (listener: () => void) => () => void;
58
+ /** New policy/callbacks affect future work; in-flight preparation is not replayed. */
59
+ configure(options: ComposerAttachmentOptions): void;
60
+ setScope(scope: ComposerScope): void;
61
+ intake(files: readonly File[], source: ComposerAttachmentSource): ComposerAttachmentAdmission;
62
+ remove(entryId: string): void;
63
+ cancel(entryId: string): void;
64
+ retry(entryId: string): boolean;
65
+ clearRejections(): void;
66
+ /** Restored binary metadata is never sufficient to mark an occurrence ready. */
67
+ restore(attachments: readonly ComposerDraftAttachment[]): void;
68
+ draftSnapshot(): readonly ComposerDraftAttachment[];
69
+ /** Throws if any selected occurrence is not ready; never silently omits files. */
70
+ sendableSnapshot(): readonly ComposerSendableAttachment[];
71
+ file(entryId: string): File | undefined;
72
+ previewUrl(entryId: string): string | undefined;
73
+ /** Releases resources and invalidates work while keeping the owner reusable. */
74
+ clear(): void;
75
+ /** Terminal disposal for controllers owned outside the React hook. */
76
+ dispose(): void;
77
+ }
78
+ export interface UseComposerAttachmentsResult extends ComposerAttachmentSnapshot {
79
+ readonly controller: ComposerAttachmentController;
80
+ }
@@ -0,0 +1,89 @@
1
+ import type { ComposerDocument, ComposerDraft, ComposerDraftAttachment, ComposerError, ComposerScope } from "./Composer.types";
2
+ export interface ComposerDraftLoadRequest {
3
+ readonly scope: ComposerScope;
4
+ readonly draftKey: string;
5
+ readonly signal: AbortSignal;
6
+ }
7
+ /**
8
+ * Host-owned storage and retention. Keep this object stable across editor mounts
9
+ * to share serialized writes. Other writers must coordinate at the storage layer.
10
+ * A save promise must settle only when that write has actually finished.
11
+ */
12
+ export interface ComposerDraftAdapter {
13
+ /** null/undefined means absent; other values are validated, including legacy strings. */
14
+ readonly load: (request: ComposerDraftLoadRequest) => Promise<unknown>;
15
+ readonly save: (draft: ComposerDraft, signal: AbortSignal) => Promise<void>;
16
+ }
17
+ export interface ComposerDraftContext {
18
+ readonly scope: ComposerScope;
19
+ readonly draftKey: string;
20
+ readonly revision: number;
21
+ readonly document: ComposerDocument;
22
+ readonly attachments?: readonly ComposerDraftAttachment[];
23
+ readonly instanceGeneration: number;
24
+ /** Distinguishes explicit replacements even if content/revision were unchanged. */
25
+ readonly originId?: string;
26
+ readonly adapter: ComposerDraftAdapter;
27
+ /** Apply an explicit restore in the editor, then echo a new controlled revision. */
28
+ readonly onRestore?: (draft: ComposerDraft) => void;
29
+ /** Preserve/export this original value; do not flatten unsupported document data. */
30
+ readonly onIncompatible?: (input: unknown, reason: string) => void;
31
+ }
32
+ /** An exact record token is required when authorizing overwrite of incompatible data. */
33
+ export interface ComposerDraftIncompatibility {
34
+ readonly input: unknown;
35
+ readonly reason: string;
36
+ readonly scope: ComposerScope;
37
+ readonly draftKey: string;
38
+ readonly instanceGeneration: number;
39
+ }
40
+ export interface ComposerDraftLoaded {
41
+ readonly draft: ComposerDraft;
42
+ readonly migrated: boolean;
43
+ /** A valid late load is retained for inspection even when newer editing wins. */
44
+ readonly applied: boolean;
45
+ }
46
+ export interface ComposerDraftSnapshot {
47
+ readonly status: "idle" | "loading" | "ready" | "error" | "incompatible";
48
+ readonly scope: ComposerScope;
49
+ readonly draftKey: string;
50
+ readonly instanceGeneration: number;
51
+ readonly saving: boolean;
52
+ /** Save is blocked until the editor acknowledges the requested controlled restore. */
53
+ readonly restorePending: boolean;
54
+ readonly overwriteAllowed: boolean;
55
+ readonly loaded?: ComposerDraftLoaded;
56
+ readonly incompatible?: ComposerDraftIncompatibility;
57
+ readonly error?: ComposerError;
58
+ readonly errorOperation?: "load" | "save" | "restore" | "incompatible";
59
+ readonly lastSavedRevision?: number;
60
+ }
61
+ export type ComposerDraftSaveResult = {
62
+ readonly outcome: "saved" | "superseded";
63
+ readonly draft: ComposerDraft;
64
+ } | {
65
+ readonly outcome: "error";
66
+ readonly draft: ComposerDraft;
67
+ readonly error: ComposerError;
68
+ } | {
69
+ readonly outcome: "blocked";
70
+ readonly reason: "inactive" | "loading" | "load_error" | "incompatible" | "restoring";
71
+ };
72
+ export interface ComposerDraftController {
73
+ readonly getSnapshot: () => ComposerDraftSnapshot;
74
+ readonly subscribe: (listener: () => void) => () => void;
75
+ /** Activating after disposal supports React StrictMode effect replay. */
76
+ activate(): void;
77
+ update(context: ComposerDraftContext): void;
78
+ reload(): Promise<void>;
79
+ /** Explicit persistence policy; no per-keystroke autosave is imposed by this controller. */
80
+ save(): Promise<ComposerDraftSaveResult>;
81
+ /** Current record only; an old context's confirmation cannot authorize another overwrite. */
82
+ allowOverwrite(incompatible: ComposerDraftIncompatibility): boolean;
83
+ /** Aborts reads. Already requested portable saves continue through the host-owned queue. */
84
+ dispose(): void;
85
+ }
86
+ export interface UseComposerDraftResult {
87
+ readonly controller: ComposerDraftController;
88
+ readonly snapshot: ComposerDraftSnapshot;
89
+ }
@@ -0,0 +1,70 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ComposerDocument, ComposerError, ComposerProvider, ComposerProviderAction, ComposerProviderCandidate, ComposerProviderRequest, ComposerProviderResult, ComposerScope } from "./Composer.types";
3
+ export interface ComposerProviderBreadcrumb {
4
+ readonly refId: string;
5
+ readonly label: string;
6
+ }
7
+ /** Runtime navigation context; it does not change the portable request schema. */
8
+ export interface ComposerProviderNavigation {
9
+ readonly breadcrumbs: readonly ComposerProviderBreadcrumb[];
10
+ readonly refId?: string;
11
+ }
12
+ export interface ComposerCompletionProvider extends ComposerProvider {
13
+ readonly label?: string;
14
+ /** Presentation only; these values do not enter the portable protocol. */
15
+ readonly icon?: ReactNode;
16
+ readonly sourceLabel?: string;
17
+ /** Commands and editable skills can share a marker with distinct providers. */
18
+ readonly trigger: {
19
+ readonly text: string;
20
+ readonly position: "leading" | "word";
21
+ };
22
+ readonly query: (request: ComposerProviderRequest, signal: AbortSignal, navigation?: ComposerProviderNavigation) => Promise<ComposerProviderResult>;
23
+ }
24
+ /** UTF-16 offsets in one semantic text node. A range selection closes suggestions. */
25
+ export interface ComposerProviderSelection {
26
+ readonly nodeIndex: number;
27
+ readonly start: number;
28
+ readonly end: number;
29
+ }
30
+ export interface ComposerProviderContext {
31
+ readonly document: ComposerDocument;
32
+ readonly documentRevision: number;
33
+ readonly scope: ComposerScope;
34
+ readonly instanceGeneration: number;
35
+ readonly selection: ComposerProviderSelection | null;
36
+ readonly providers: readonly ComposerCompletionProvider[];
37
+ /** Adapter/host availability, independent of a provider's own disabled reason. */
38
+ readonly candidateDisabledReason?: (candidate: ComposerProviderCandidate) => string | undefined;
39
+ }
40
+ export interface ComposerProviderItem {
41
+ /** Stable, DOM-safe identity derived from providerId and candidate.id. */
42
+ readonly id: string;
43
+ readonly providerId: string;
44
+ readonly candidate: ComposerProviderCandidate;
45
+ readonly request: ComposerProviderRequest;
46
+ }
47
+ export type ComposerProviderStatus = "idle" | "loading" | "ready" | "empty" | "error";
48
+ export interface ComposerProviderGroup {
49
+ readonly providerId: string;
50
+ readonly label: string;
51
+ readonly status: Exclude<ComposerProviderStatus, "idle">;
52
+ readonly items: readonly ComposerProviderItem[];
53
+ readonly request: ComposerProviderRequest;
54
+ readonly error?: ComposerError;
55
+ }
56
+ export interface ComposerProviderSnapshot {
57
+ readonly status: ComposerProviderStatus;
58
+ readonly groups: readonly ComposerProviderGroup[];
59
+ readonly items: readonly ComposerProviderItem[];
60
+ readonly activeId?: string;
61
+ readonly breadcrumbs: readonly ComposerProviderBreadcrumb[];
62
+ readonly error?: ComposerError;
63
+ }
64
+ /** Apply this action once, in the adapter transaction for the captured request. */
65
+ export interface ComposerProviderSelectionEffect {
66
+ readonly itemId: string;
67
+ readonly request: ComposerProviderRequest;
68
+ readonly candidate: ComposerProviderCandidate;
69
+ readonly action: ComposerProviderAction;
70
+ }
@@ -0,0 +1,64 @@
1
+ import type React from "react";
2
+ import type { ComposerCapabilities, ComposerDocument, ComposerQueueItem, ComposerQueueMutation, ComposerQueueMutationResult, ComposerQueueProjection } from "./Composer.types";
3
+ export interface ComposerQueueEditorProps {
4
+ readonly item: ComposerQueueItem;
5
+ readonly value: ComposerDocument;
6
+ readonly onChange: (document: ComposerDocument) => void;
7
+ readonly onSave: () => void;
8
+ readonly onCancel: () => void;
9
+ readonly pending: boolean;
10
+ }
11
+ export interface ChatAuthoritativeQueueProps {
12
+ readonly projection: ComposerQueueProjection;
13
+ readonly capabilities: ComposerCapabilities["queue"];
14
+ readonly targetTurnId?: string;
15
+ readonly onMutation: (mutation: ComposerQueueMutation, signal: AbortSignal) => Promise<ComposerQueueMutationResult>;
16
+ /** Apply the canonical projection, including rejected/conflicting operations. */
17
+ readonly onProjection: (projection: ComposerQueueProjection) => void;
18
+ /** Required for structured document edits. Attachments remain host-owned. */
19
+ readonly renderDocumentEditor?: (props: ComposerQueueEditorProps) => React.ReactNode;
20
+ readonly label?: string;
21
+ readonly className?: string;
22
+ }
23
+ export interface ComposerSettingChoice {
24
+ readonly value: string;
25
+ readonly label: string;
26
+ readonly unavailableReason?: string;
27
+ }
28
+ export interface ComposerSetting {
29
+ readonly id: string;
30
+ readonly label: string;
31
+ readonly value: string;
32
+ readonly choices: readonly ComposerSettingChoice[];
33
+ readonly unavailableReason?: string;
34
+ }
35
+ export interface ComposerSettingRequest {
36
+ readonly requestId: string;
37
+ readonly scopeKey: string;
38
+ readonly settingId: string;
39
+ readonly expectedRevision: number;
40
+ readonly value: string;
41
+ }
42
+ export type ComposerSettingResult = {
43
+ readonly requestId: string;
44
+ readonly scopeKey: string;
45
+ readonly settingId: string;
46
+ readonly revision: number;
47
+ } & ({
48
+ readonly outcome: "accepted";
49
+ readonly value: string;
50
+ } | {
51
+ readonly outcome: "rejected";
52
+ readonly message: string;
53
+ });
54
+ export interface ComposerSettingsProps {
55
+ readonly scopeKey: string;
56
+ readonly revision: number;
57
+ readonly settings: readonly ComposerSetting[];
58
+ /** Requests are serialized because all settings share one authoritative revision. */
59
+ readonly onRequest: (request: ComposerSettingRequest, signal: AbortSignal) => Promise<ComposerSettingResult>;
60
+ /** Host applies acknowledged values; selection stays controlled until then. */
61
+ readonly onAcknowledged: (result: ComposerSettingResult) => void;
62
+ readonly label?: string;
63
+ readonly className?: string;
64
+ }
@@ -0,0 +1,78 @@
1
+ import type { ComposerCapabilities, ComposerCommand, ComposerDocument, ComposerError, ComposerIntent, ComposerJson, ComposerReceipt, ComposerScope, ComposerSendableAttachment, ComposerSubmission } from "./Composer.types";
2
+ /** Run state is independent of admission, editing, and attachment preparation. */
3
+ export interface ComposerRuntimeState {
4
+ readonly status: "idle" | "running" | "disconnected" | "read_only";
5
+ readonly activeTurnId?: string;
6
+ }
7
+ export interface ComposerActionPolicy {
8
+ /** Default while a run is active. Never implies that the host supports it. */
9
+ readonly runningIntent?: "follow_up" | "steer";
10
+ /** Plain Composer keeps its historical shortcut unless explicitly selected. */
11
+ readonly shortcut?: "modifier_enter" | "enter";
12
+ }
13
+ export interface ComposerAttempt {
14
+ readonly snapshot: ComposerSubmission;
15
+ readonly instanceId: string;
16
+ readonly instanceGeneration: number;
17
+ readonly createdAt: number;
18
+ readonly status: "pending" | "accepted" | "rejected" | "unknown";
19
+ readonly receipt?: ComposerReceipt;
20
+ }
21
+ /**
22
+ * An application-owned object that outlives an editor mount. Retention does not
23
+ * itself promise reload persistence. Never evict pending/unknown attempts.
24
+ */
25
+ export interface ComposerRecoveryOwner {
26
+ readonly getSnapshot: () => readonly ComposerAttempt[];
27
+ readonly subscribe: (listener: () => void) => () => void;
28
+ readonly retain: (attempt: ComposerAttempt) => void;
29
+ }
30
+ export interface ComposerSessionHost {
31
+ readonly capabilities: ComposerCapabilities;
32
+ readonly recovery: ComposerRecoveryOwner;
33
+ readonly submit: (snapshot: ComposerSubmission, signal: AbortSignal) => Promise<ComposerReceipt>;
34
+ /** A missing record is still unresolved; lookup never implicitly retries. */
35
+ readonly reconcile?: (snapshot: ComposerSubmission, signal: AbortSignal) => Promise<ComposerReceipt | {
36
+ readonly outcome: "not_found";
37
+ }>;
38
+ /** Explicit host authorization is required before resending the SAME snapshot. */
39
+ readonly authorizeRetry?: (attempt: ComposerAttempt) => Promise<boolean>;
40
+ /** The host catalog distinguishes prompt commands from non-prompt actions. */
41
+ readonly commandOperation?: (command: ComposerCommand) => "prompt" | "command";
42
+ }
43
+ export interface ComposerSessionContext {
44
+ readonly scope: ComposerScope;
45
+ readonly draftKey: string;
46
+ readonly document: ComposerDocument;
47
+ readonly revision: number;
48
+ readonly instanceGeneration: number;
49
+ readonly runtime: ComposerRuntimeState;
50
+ readonly host: ComposerSessionHost;
51
+ readonly policy?: ComposerActionPolicy;
52
+ readonly attachments?: readonly ComposerSendableAttachment[];
53
+ readonly attachmentsPending?: boolean;
54
+ readonly options?: Readonly<Record<string, ComposerJson>>;
55
+ readonly disabled?: boolean;
56
+ readonly busy?: boolean;
57
+ readonly canSubmit?: boolean;
58
+ readonly allowAttachmentOnly?: boolean;
59
+ /** Called only for the exact still-current submitted document revision. */
60
+ readonly onAccepted?: (snapshot: ComposerSubmission) => void;
61
+ /** Attachment clearing uses occurrence identity, independently of text edits. */
62
+ readonly onAcceptedAttachments?: (attachments: readonly ComposerSendableAttachment[]) => void;
63
+ }
64
+ export interface ComposerActionEligibility {
65
+ readonly allowed: boolean;
66
+ readonly intent?: ComposerIntent;
67
+ readonly operation: "prompt" | "command";
68
+ readonly label: string;
69
+ readonly reason?: string;
70
+ }
71
+ export interface ComposerSessionSnapshot {
72
+ readonly submitting: boolean;
73
+ readonly error?: ComposerError;
74
+ readonly lastReceipt?: ComposerReceipt;
75
+ /** Failed host handoffs remain inspectable, including after disposal. Export or
76
+ * persist these snapshots before discarding their controller. No auto-retry. */
77
+ readonly recoveryFailures?: readonly ComposerAttempt[];
78
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { ComposerSettingsProps } from "./ComposerQueue.types";
3
+ /** Host-owned choices and values. A click requests a change, never confirms it. */
4
+ export declare function ComposerSettings(props: ComposerSettingsProps): React.JSX.Element;
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import type { ChatComposerCompletion } from "../Chat.types";
3
+ export declare function completionOptionId(composerId: string, candidateId: string): string;
4
+ export declare function CompletionList({ composerId, label, candidates, activeId, onSelect, compact, anchorName, header, status, onDismiss, }: {
5
+ composerId: string;
6
+ label: string;
7
+ candidates: readonly ChatComposerCompletion[];
8
+ activeId?: string;
9
+ onSelect: (item: ChatComposerCompletion) => void;
10
+ compact?: boolean;
11
+ anchorName?: string;
12
+ header?: React.ReactNode;
13
+ status?: React.ReactNode;
14
+ onDismiss?: () => void;
15
+ }): React.JSX.Element;
@@ -1,13 +1,26 @@
1
1
  import React from "react";
2
2
  import type { ChatComposerCompletion, ChatComposerProps } from "../Chat.types";
3
- import type { AttachmentEntry } from "./legacy";
3
+ import type { ComposerAttachmentSource } from "../ComposerAttachment.types";
4
+ export interface ComposerShellAttachment {
5
+ id: number | string;
6
+ file?: File;
7
+ name?: string;
8
+ previewUrl?: string;
9
+ state?: string;
10
+ status?: React.ReactNode;
11
+ progress?: number;
12
+ retry?: () => void;
13
+ cancel?: () => void;
14
+ }
4
15
  interface ComposerShellProps extends Omit<React.ComponentProps<"div">, "children" | "onSubmit"> {
5
16
  editor: React.ReactNode;
6
17
  composerId: string;
7
- entries: readonly AttachmentEntry[];
18
+ compact?: boolean;
19
+ addMenu?: React.ReactNode;
20
+ entries: readonly ComposerShellAttachment[];
8
21
  renderAttachment?: ChatComposerProps["renderAttachment"];
9
- removeAttachment: (id: number) => void;
10
- addAttachments: (files: File[]) => void;
22
+ removeAttachment: (id: number | string) => void;
23
+ addAttachments: (files: File[], source: ComposerAttachmentSource) => void;
11
24
  onAttachmentsChange?: ChatComposerProps["onAttachmentsChange"];
12
25
  pickerRef: React.RefObject<HTMLInputElement | null>;
13
26
  accept?: string;
@@ -22,8 +35,14 @@ interface ComposerShellProps extends Omit<React.ComponentProps<"div">, "children
22
35
  active?: ChatComposerCompletion;
23
36
  showCompletion: boolean;
24
37
  selectCompletion: (item: ChatComposerCompletion) => void;
38
+ dismissCompletion?: () => void;
25
39
  visibleError: React.ReactNode;
26
40
  hasError: boolean;
41
+ intakeEvents?: boolean;
42
+ completionHeader?: React.ReactNode;
43
+ completionStatus?: React.ReactNode;
44
+ statusContent?: React.ReactNode;
45
+ renderFooter?: (renderToolbar: (menuContent?: React.ReactNode) => React.ReactNode) => React.ReactNode;
27
46
  attachLabel: string;
28
47
  sendLabel: string;
29
48
  stopLabel: string;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import type { ComposerDocumentUpdate, ComposerScope } from "../Composer.types";
3
+ import type { ComposerDraftAdapter } from "../ComposerDraft.types";
4
+ import type { ComposerAttachmentController } from "../ComposerAttachment.types";
5
+ interface Props {
6
+ adapter: ComposerDraftAdapter;
7
+ scope: ComposerScope;
8
+ draftKey: string;
9
+ generation: number;
10
+ value: ComposerDocumentUpdate;
11
+ attachments: ComposerAttachmentController;
12
+ onDocumentChange: (value: ComposerDocumentUpdate) => void;
13
+ disabled: boolean;
14
+ compact?: boolean;
15
+ children: (feedback: React.ReactNode, menuActions?: React.ReactNode) => React.ReactNode;
16
+ }
17
+ /** Host storage is optional; no autosave cadence or browser storage is assumed. */
18
+ export declare function DraftLifecycle({ adapter, scope, draftKey, generation, value, attachments, onDocumentChange, disabled, compact, children, }: Props): React.ReactNode;
19
+ export {};
@@ -0,0 +1,36 @@
1
+ import type React from "react";
2
+ import type { ComposerCommand, ComposerDocumentUpdate, ComposerQuoteNode, ComposerReferenceNode } from "../Composer.types";
3
+ import type { ComposerProviderSelection, ComposerProviderSelectionEffect } from "../ComposerProvider.types";
4
+ /** Public semantic insertion commands never expose editor classes or node keys. */
5
+ export interface ComposerEditorHandle {
6
+ focus: () => void;
7
+ insertReference: (reference: ComposerReferenceNode) => void;
8
+ insertQuote: (quote: ComposerQuoteNode) => void;
9
+ claimCommand: (command: ComposerCommand, source: string) => void;
10
+ insertText: (text: string) => void;
11
+ applyProvider: (effect: ComposerProviderSelectionEffect) => boolean;
12
+ selection: () => ComposerProviderSelection | null;
13
+ }
14
+ /** Private adapter boundary; the wrapper owns providers/admission, never history. */
15
+ export interface ComposerEditorAdapterProps {
16
+ readonly value: ComposerDocumentUpdate;
17
+ readonly onChange: (value: ComposerDocumentUpdate) => void;
18
+ readonly onSelectionChange: (selection: ComposerProviderSelection | null) => void;
19
+ readonly instanceGeneration: number;
20
+ readonly disabled?: boolean;
21
+ readonly minRows?: number;
22
+ readonly maxRows?: number;
23
+ readonly id: string;
24
+ readonly label: string;
25
+ readonly describedBy?: string;
26
+ readonly invalid?: boolean;
27
+ readonly controls?: string;
28
+ readonly activeDescendant?: string;
29
+ readonly hasSuggestions?: boolean;
30
+ /** Invoked only after the adapter's IME/229 and consumer preventDefault gates. */
31
+ readonly onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
32
+ readonly onPaste?: React.ClipboardEventHandler<HTMLDivElement>;
33
+ readonly onDrop?: React.DragEventHandler<HTMLDivElement>;
34
+ readonly onError?: (error: Error) => void;
35
+ readonly onReady?: (ready: boolean) => void;
36
+ }
@@ -3,6 +3,7 @@ import type { ChatComposerCompletionContext, ChatComposerProps } from "../Chat.t
3
3
  export interface PlainEditorHandle {
4
4
  focus: () => void;
5
5
  selection: (value: string) => ChatComposerCompletionContext;
6
+ select: (start: number, end: number) => void;
6
7
  }
7
8
  interface PlainEditorProps {
8
9
  value: string;
@@ -16,6 +17,7 @@ interface PlainEditorProps {
16
17
  hasCompletion: boolean;
17
18
  showCompletion: boolean;
18
19
  activeIndex: number;
20
+ activeDescendant?: string;
19
21
  onChange: (value: string) => void;
20
22
  onKeyDown: React.KeyboardEventHandler<HTMLTextAreaElement>;
21
23
  }
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import type { ComposerDocument } from "../Composer.types";
3
+ import type { ComposerEditorAdapterProps, ComposerEditorHandle } from "./EditorAdapter.types";
4
+ export declare function isPlainComposerDocument(document: ComposerDocument): boolean;
5
+ /** Native textarea adapter for protocol sessions; structured data is never flattened. */
6
+ export declare const PlainSemanticEditor: React.ForwardRefExoticComponent<ComposerEditorAdapterProps & React.RefAttributes<ComposerEditorHandle>>;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ /** A failed/unsupported editor never replaces the host's semantic draft with text. */
3
+ export declare function PreservedDraft({ input, reason, state, }: {
4
+ input: unknown;
5
+ reason: string;
6
+ state?: "error" | "unknown" | "pending";
7
+ }): React.JSX.Element;