@duskmoon-dev/components 0.5.4 → 0.5.6

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/README.md CHANGED
@@ -70,8 +70,8 @@ Chat docs include RTL, live states, tool statuses, message actions and the Core
70
70
  `Chat.Work`, `Chat.WorkSummary` and `Chat.WorkBody` disclosures, keeping the final
71
71
  answer outside them. User messages use `Chat placement="end"` and `Chat.Bubble`;
72
72
  opt into `collapsible` for automatic six-line measurement, resize/text updates,
73
- accessible expansion and focus cleanup. All new Chat primitives require Core
74
- 1.20.6, which is the package peer minimum.
73
+ accessible expansion and focus cleanup. The package now requires Core 1.21.0,
74
+ which supplies the shared Composer editor, attachment, suggestion and status parts.
75
75
 
76
76
  `Chat.InputArea` attaches a controlled `Chat.Queue` to native
77
77
  `Chat.ComposerForm`, `Chat.ComposerInput`, `Chat.ComposerActions` and
@@ -87,6 +87,26 @@ The existing controlled `Chat.Composer` retains its div ref, attachment and
87
87
  completion APIs, revision-safe asynchronous draft clearing, and Cmd/Ctrl+Enter
88
88
  submission with ordinary Enter for newlines. Use the native composer primitives
89
89
  when form submission and the reference's Enter-to-queue contract are needed.
90
+ Supply `scope={{ contextKey, conversationId }}` when reusing a Composer between
91
+ repositories or conversations: a late acceptance or error from the previous
92
+ scope cannot clear the current draft or call its error handler. Pending admission
93
+ leaves editing available. The host still owns the controlled draft and files.
94
+
95
+ Root and `/chat` exports also provide editor-independent `ComposerDocument`,
96
+ `ComposerDraft`, submission/receipt, provider, attachment and queue types.
97
+ `readComposerDocument` and `readComposerDraft` preserve incompatible input for
98
+ recovery; `snapshotComposerDocument` and `snapshotComposerSubmission` validate,
99
+ copy and freeze portable JSON. `exportComposerText` and `exportComposerMarkdown`
100
+ project references through `plainText` and retain quote attribution. Invalid
101
+ snapshots throw instead of silently discarding unsupported fields. Portable
102
+ examples are published at `@duskmoon-dev/components/chat/contracts.v1.json`.
103
+ These contracts are integration groundwork; the optional rich editor, upload
104
+ transport, provider lookup and authoritative queue mutation remain separate work.
105
+
106
+ Core 1.21.0 still has a known Moonlight contrast gap for neutral outlined/ghost
107
+ labels ([duskmoonui#78](https://github.com/duskmoon-dev/duskmoonui/issues/78)).
108
+ The upstream fix is required before claiming complete palette accessibility.
109
+
90
110
  Existing `Chat.Bubble streaming` remains usable; `Chat.Content streaming` is the
91
111
  preferred agent presentation. No public Chat API is removed or deprecated.
92
112
 
@@ -2448,6 +2448,7 @@ var timelineBaseClass = "timeline";
2448
2448
  var timelineItemClass = "timeline-item";
2449
2449
  var timelineMarkerBaseClass = "timeline-marker";
2450
2450
  var timelineMarkerIconClass = "timeline-marker-icon";
2451
+ var timelineMarkerDotClass = "timeline-marker-dot";
2451
2452
  var timelineContentClass = "timeline-content";
2452
2453
  var timelineTimeClass = "timeline-time";
2453
2454
  var timelinePendingClass = "timeline-item-pending";
@@ -3787,6 +3788,7 @@ export {
3787
3788
  timelineItemClass,
3788
3789
  timelineMarkerBaseClass,
3789
3790
  timelineMarkerColorClasses,
3791
+ timelineMarkerDotClass,
3790
3792
  timelineMarkerIconClass,
3791
3793
  timelineModeClasses,
3792
3794
  timelinePendingClass,
@@ -3,6 +3,7 @@ export declare const timelineBaseClass = "timeline";
3
3
  export declare const timelineItemClass = "timeline-item";
4
4
  export declare const timelineMarkerBaseClass = "timeline-marker";
5
5
  export declare const timelineMarkerIconClass = "timeline-marker-icon";
6
+ export declare const timelineMarkerDotClass = "timeline-marker-dot";
6
7
  export declare const timelineContentClass = "timeline-content";
7
8
  export declare const timelineTimeClass = "timeline-time";
8
9
  export declare const timelinePendingClass = "timeline-item-pending";
@@ -1,5 +1,6 @@
1
1
  import type { ComponentProps, ForwardRefExoticComponent, RefAttributes, ReactNode } from "react";
2
2
  import type { TextAreaProps } from "../input";
3
+ import type { ComposerScope } from "./Composer.types";
3
4
  export type ChatPlacement = "start" | "end";
4
5
  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;
5
6
  export type ChatBubbleColor = "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error";
@@ -126,6 +127,8 @@ export interface ChatComposerAttachmentContext {
126
127
  }
127
128
  export interface ChatComposerProps extends Omit<ComponentProps<"div">, "children" | "onSubmit" | "onChange"> {
128
129
  value: string;
130
+ /** Isolate pending admission and completion state when changing contexts. */
131
+ scope?: ComposerScope;
129
132
  onValueChange: (value: string) => void;
130
133
  /** Return false to reject admission and retain the draft. */
131
134
  onSubmit: (snapshot: ChatComposerSubmission) => boolean | void | Promise<boolean | void>;
@@ -0,0 +1,270 @@
1
+ /** Portable JSON values. Application adapters must validate their meaning. */
2
+ export type ComposerJson = null | boolean | number | string | readonly ComposerJson[] | {
3
+ readonly [key: string]: ComposerJson;
4
+ };
5
+ /** Both fields are opaque identities, never client-side authorization. */
6
+ export interface ComposerScope {
7
+ readonly contextKey: string;
8
+ readonly conversationId: string;
9
+ }
10
+ export interface ComposerTextNode {
11
+ readonly type: "text";
12
+ readonly text: string;
13
+ }
14
+ export interface ComposerReferenceNode {
15
+ readonly type: "reference";
16
+ /** Identity of this occurrence, distinct from the provider's target. */
17
+ readonly nodeId: string;
18
+ readonly providerId: string;
19
+ readonly refId: string;
20
+ readonly label: string;
21
+ readonly plainText: string;
22
+ }
23
+ /** Untrusted provenance; the application resolves and authorizes the source. */
24
+ export interface ComposerQuoteSource {
25
+ readonly providerId?: string;
26
+ readonly refId?: string;
27
+ readonly label?: string;
28
+ readonly messageId?: string;
29
+ readonly conversationId?: string;
30
+ }
31
+ export interface ComposerQuoteNode {
32
+ readonly type: "quote";
33
+ readonly nodeId: string;
34
+ readonly text: string;
35
+ readonly source?: ComposerQuoteSource;
36
+ }
37
+ export type ComposerNode = ComposerTextNode | ComposerReferenceNode | ComposerQuoteNode;
38
+ export interface ComposerCommand {
39
+ readonly providerId: string;
40
+ readonly commandId: string;
41
+ }
42
+ export interface ComposerDocument {
43
+ readonly schemaVersion: 1;
44
+ readonly content: readonly ComposerNode[];
45
+ /** Claimed leading command; argument interpretation belongs to its provider. */
46
+ readonly command?: ComposerCommand;
47
+ }
48
+ export type ComposerDocumentOrigin = "edit" | "replace" | "restore" | "scope_switch" | "clear";
49
+ /** Echo the same originId/revision without resetting selection or history. */
50
+ export interface ComposerDocumentUpdate {
51
+ readonly document: ComposerDocument;
52
+ readonly revision: number;
53
+ readonly origin: ComposerDocumentOrigin;
54
+ readonly originId: string;
55
+ }
56
+ export interface ComposerAttachmentMetadata {
57
+ readonly name: string;
58
+ readonly mediaType: string;
59
+ readonly size: number;
60
+ readonly lastModified?: number;
61
+ }
62
+ /** Application-issued reference or receipt; contains no local binary handle. */
63
+ export interface ComposerAttachmentHandle {
64
+ readonly providerId: string;
65
+ readonly reference: ComposerJson;
66
+ }
67
+ export interface ComposerSendableAttachment {
68
+ readonly entryId: string;
69
+ readonly metadata: ComposerAttachmentMetadata;
70
+ readonly handle: ComposerAttachmentHandle;
71
+ }
72
+ export type ComposerAttachmentState = {
73
+ readonly status: "preparing" | "uploading";
74
+ readonly progress?: number;
75
+ } | {
76
+ readonly status: "ready";
77
+ readonly handle: ComposerAttachmentHandle;
78
+ } | {
79
+ readonly status: "error";
80
+ readonly error: ComposerError;
81
+ } | {
82
+ readonly status: "cancelled" | "reattach";
83
+ };
84
+ /** One selected occurrence; removing/reselecting a file creates a new entryId. */
85
+ export interface ComposerAttachmentEntry {
86
+ readonly entryId: string;
87
+ readonly metadata: ComposerAttachmentMetadata;
88
+ readonly state: ComposerAttachmentState;
89
+ }
90
+ export type ComposerDraftAttachment = {
91
+ readonly entryId: string;
92
+ readonly metadata: ComposerAttachmentMetadata;
93
+ } & ({
94
+ readonly status: "reattach";
95
+ } | {
96
+ readonly status: "ready";
97
+ readonly handle: ComposerAttachmentHandle;
98
+ });
99
+ export interface ComposerDraft {
100
+ readonly draftVersion: 1;
101
+ readonly scope: ComposerScope;
102
+ readonly draftKey: string;
103
+ readonly revision: number;
104
+ readonly document: ComposerDocument;
105
+ readonly attachments: readonly ComposerDraftAttachment[];
106
+ }
107
+ export interface ComposerError {
108
+ readonly code: string;
109
+ readonly message: string;
110
+ readonly details?: ComposerJson;
111
+ }
112
+ export type ComposerIntent = "send" | "follow_up" | "steer";
113
+ export type ComposerDelivery = "immediate" | "follow_up" | "steer";
114
+ interface ComposerSubmissionBase {
115
+ readonly protocolVersion: 1;
116
+ /** Reused only for reconciliation or an explicitly authorized retry. */
117
+ readonly clientSubmissionId: string;
118
+ readonly scope: ComposerScope;
119
+ readonly draftKey: string;
120
+ readonly draftRevision: number;
121
+ readonly document: ComposerDocument;
122
+ readonly attachments: readonly ComposerSendableAttachment[];
123
+ readonly options: Readonly<Record<string, ComposerJson>>;
124
+ }
125
+ export type ComposerPromptSubmission = ComposerSubmissionBase & {
126
+ readonly operation: "prompt";
127
+ } & ({
128
+ readonly intent: "send" | "follow_up";
129
+ readonly targetTurnId?: never;
130
+ } | {
131
+ readonly intent: "steer";
132
+ readonly targetTurnId: string;
133
+ });
134
+ export type ComposerCommandSubmission = ComposerSubmissionBase & {
135
+ readonly operation: "command";
136
+ readonly document: ComposerDocument & {
137
+ readonly command: ComposerCommand;
138
+ };
139
+ readonly intent?: never;
140
+ readonly targetTurnId?: never;
141
+ };
142
+ export type ComposerSubmission = ComposerPromptSubmission | ComposerCommandSubmission;
143
+ interface ComposerReceiptBase {
144
+ readonly protocolVersion: 1;
145
+ readonly clientSubmissionId: string;
146
+ readonly scope: ComposerScope;
147
+ }
148
+ export type ComposerAcceptedPromptReceipt = ComposerReceiptBase & {
149
+ readonly outcome: "accepted";
150
+ readonly operation: "prompt";
151
+ readonly delivery: ComposerDelivery;
152
+ /** Admission, not completed generation or exactly-once execution. */
153
+ readonly persistence: "volatile" | "durable";
154
+ readonly messageId?: string;
155
+ readonly turnId?: string;
156
+ readonly queueItemId?: string;
157
+ readonly queueRevision?: number;
158
+ };
159
+ export type ComposerAcceptedCommandReceipt = ComposerReceiptBase & {
160
+ readonly outcome: "accepted";
161
+ readonly operation: "command";
162
+ readonly result: ComposerJson;
163
+ readonly delivery?: never;
164
+ readonly persistence?: never;
165
+ readonly messageId?: never;
166
+ readonly turnId?: never;
167
+ readonly queueItemId?: never;
168
+ };
169
+ export type ComposerUnresolvedReceipt = ComposerReceiptBase & {
170
+ readonly outcome: "rejected" | "unknown";
171
+ readonly operation: "prompt" | "command";
172
+ readonly error: ComposerError;
173
+ };
174
+ export type ComposerReceipt = ComposerAcceptedPromptReceipt | ComposerAcceptedCommandReceipt | ComposerUnresolvedReceipt;
175
+ /** Portable request identity. Offsets are local UTF-16 offsets, not server ranges. */
176
+ export interface ComposerProviderRequest {
177
+ readonly requestId: string;
178
+ readonly providerId: string;
179
+ readonly scope: ComposerScope;
180
+ readonly instanceGeneration: number;
181
+ readonly documentRevision: number;
182
+ readonly query: string;
183
+ readonly trigger: {
184
+ readonly text: string;
185
+ readonly nodeIndex: number;
186
+ readonly start: number;
187
+ readonly end: number;
188
+ readonly caret: number;
189
+ };
190
+ }
191
+ export type ComposerProviderAction = {
192
+ readonly type: "insert";
193
+ readonly content: readonly ComposerNode[];
194
+ readonly command?: ComposerCommand;
195
+ } | {
196
+ readonly type: "drill";
197
+ readonly refId: string;
198
+ } | {
199
+ readonly type: "invoke";
200
+ readonly command: ComposerCommand;
201
+ readonly arguments?: ComposerJson;
202
+ };
203
+ export interface ComposerProviderCandidate {
204
+ readonly id: string;
205
+ readonly label: string;
206
+ readonly description?: string;
207
+ readonly group?: string;
208
+ readonly disabledReason?: string;
209
+ readonly action: ComposerProviderAction;
210
+ }
211
+ export interface ComposerProviderResult {
212
+ readonly request: ComposerProviderRequest;
213
+ readonly candidates: readonly ComposerProviderCandidate[];
214
+ }
215
+ /** Runtime callback boundary. Cancellation is separate from the portable request. */
216
+ export interface ComposerProvider {
217
+ readonly providerId: string;
218
+ readonly query: (request: ComposerProviderRequest, signal: AbortSignal) => Promise<ComposerProviderResult>;
219
+ }
220
+ export interface ComposerCapabilities {
221
+ readonly protocolVersion: 1;
222
+ readonly documentVersions: readonly number[];
223
+ readonly intents: readonly ComposerIntent[];
224
+ readonly commands: boolean;
225
+ readonly attachments: boolean;
226
+ readonly queue: {
227
+ readonly edit: "none" | "text" | "document";
228
+ readonly remove: boolean;
229
+ readonly promote: boolean;
230
+ };
231
+ /** Only the host can advertise persistence and reconciliation guarantees. */
232
+ readonly durableRecovery: boolean;
233
+ }
234
+ export interface ComposerQueueItem {
235
+ readonly id: string;
236
+ readonly document: ComposerDocument;
237
+ readonly attachments: readonly ComposerSendableAttachment[];
238
+ readonly capabilities: ComposerCapabilities["queue"];
239
+ }
240
+ /** Confirmed authoritative membership/order; pending admissions are separate. */
241
+ export interface ComposerQueueProjection {
242
+ readonly protocolVersion: 1;
243
+ readonly scope: ComposerScope;
244
+ readonly revision: number;
245
+ readonly items: readonly ComposerQueueItem[];
246
+ }
247
+ export type ComposerQueueMutation = {
248
+ readonly requestId: string;
249
+ readonly scope: ComposerScope;
250
+ readonly itemId: string;
251
+ readonly expectedRevision: number;
252
+ } & ({
253
+ readonly operation: "remove";
254
+ } | {
255
+ readonly operation: "edit";
256
+ readonly document: ComposerDocument;
257
+ } | {
258
+ readonly operation: "promote";
259
+ readonly targetTurnId: string;
260
+ });
261
+ export type ComposerQueueMutationResult = {
262
+ readonly requestId: string;
263
+ readonly projection: ComposerQueueProjection;
264
+ } & ({
265
+ readonly outcome: "accepted";
266
+ } | {
267
+ readonly outcome: "rejected";
268
+ readonly error: ComposerError;
269
+ });
270
+ export {};
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import type { ChatComposerCompletion, ChatComposerProps } from "../Chat.types";
3
+ import type { AttachmentEntry } from "./legacy";
4
+ interface ComposerShellProps extends Omit<React.ComponentProps<"div">, "children" | "onSubmit"> {
5
+ editor: React.ReactNode;
6
+ composerId: string;
7
+ entries: readonly AttachmentEntry[];
8
+ renderAttachment?: ChatComposerProps["renderAttachment"];
9
+ removeAttachment: (id: number) => void;
10
+ addAttachments: (files: File[]) => void;
11
+ onAttachmentsChange?: ChatComposerProps["onAttachmentsChange"];
12
+ pickerRef: React.RefObject<HTMLInputElement | null>;
13
+ accept?: string;
14
+ multiple: boolean;
15
+ disabled: boolean;
16
+ busy: boolean;
17
+ submitting: boolean;
18
+ generating: boolean;
19
+ eligible: boolean;
20
+ completion?: ChatComposerProps["completion"];
21
+ candidates: readonly ChatComposerCompletion[];
22
+ active?: ChatComposerCompletion;
23
+ showCompletion: boolean;
24
+ selectCompletion: (item: ChatComposerCompletion) => void;
25
+ visibleError: React.ReactNode;
26
+ hasError: boolean;
27
+ attachLabel: string;
28
+ sendLabel: string;
29
+ stopLabel: string;
30
+ openAttachments: () => void;
31
+ submit: () => Promise<void>;
32
+ onStop?: () => void;
33
+ children?: ChatComposerProps["children"];
34
+ }
35
+ /** Shared presentation; editors own their DOM, selection and composition. */
36
+ export declare const ComposerShell: React.ForwardRefExoticComponent<Omit<ComposerShellProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
37
+ export {};
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import type { ChatComposerCompletionContext, ChatComposerProps } from "../Chat.types";
3
+ export interface PlainEditorHandle {
4
+ focus: () => void;
5
+ selection: (value: string) => ChatComposerCompletionContext;
6
+ }
7
+ interface PlainEditorProps {
8
+ value: string;
9
+ disabled: boolean;
10
+ minRows: number;
11
+ maxRows: number;
12
+ generation: number;
13
+ textareaProps?: ChatComposerProps["textareaProps"];
14
+ composerId: string;
15
+ hasError: boolean;
16
+ hasCompletion: boolean;
17
+ showCompletion: boolean;
18
+ activeIndex: number;
19
+ onChange: (value: string) => void;
20
+ onKeyDown: React.KeyboardEventHandler<HTMLTextAreaElement>;
21
+ }
22
+ /** Native textarea adapter; controlled echoes retain the same editor DOM. */
23
+ export declare const PlainEditor: React.ForwardRefExoticComponent<PlainEditorProps & React.RefAttributes<PlainEditorHandle>>;
24
+ export {};
@@ -0,0 +1,38 @@
1
+ /** Compile-only compatibility fixtures: this module contains no runtime imports. */
2
+ import type { ComponentProps, KeyboardEvent, Ref } from "react";
3
+ import type { ChatComponent, ChatComposerProps, ChatComposerSubmission } from "../Chat.types";
4
+ import type { ComposerAcceptedCommandReceipt, ComposerCommandSubmission, ComposerPromptSubmission } from "../Composer.types";
5
+ type Assert<T extends true> = T;
6
+ type LegacyPlainConsumer = {
7
+ value: string;
8
+ onValueChange: (value: string) => void;
9
+ onSubmit: (snapshot: ChatComposerSubmission) => Promise<boolean | void>;
10
+ attachments: File[];
11
+ onAttachmentsChange: (files: File[]) => void;
12
+ textareaProps: {
13
+ name: string;
14
+ "aria-label": string;
15
+ onKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
16
+ };
17
+ };
18
+ /** A current consumer needs no new rich props and retains textarea forwarding. */
19
+ export type PlainComposerCompatibility = Assert<LegacyPlainConsumer extends ChatComposerProps ? true : false>;
20
+ export type PlainComposerRefCompatibility = Assert<Ref<HTMLDivElement> extends ComponentProps<ChatComponent["Composer"]>["ref"] ? true : false>;
21
+ type SteeringWithoutTarget = Omit<Extract<ComposerPromptSubmission, {
22
+ intent: "steer";
23
+ }>, "targetTurnId">;
24
+ export type SteeringRequiresTarget = Assert<SteeringWithoutTarget extends ComposerPromptSubmission ? false : true>;
25
+ type CommandWithoutClaim = Omit<ComposerCommandSubmission, "document"> & {
26
+ document: {
27
+ schemaVersion: 1;
28
+ content: [];
29
+ };
30
+ };
31
+ export type CommandRequiresClaim = Assert<CommandWithoutClaim extends ComposerCommandSubmission ? false : true>;
32
+ export type CommandCannotInventPromptIdentity = Assert<ComposerAcceptedCommandReceipt & {
33
+ turnId: string;
34
+ } extends never ? true : false>;
35
+ export type CommandCannotInventPromptDelivery = Assert<ComposerAcceptedCommandReceipt & {
36
+ delivery: "immediate";
37
+ } extends never ? true : false>;
38
+ export {};