@duskmoon-dev/components 0.5.6 → 0.6.0

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 (41) hide show
  1. package/README.md +85 -2
  2. package/dist/chunk-b1jnq16e.js +727 -0
  3. package/dist/chunk-kg46s2vk.js +238 -0
  4. package/dist/components/chat/Chat.types.d.ts +8 -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 +42 -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 +66 -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 +10 -0
  15. package/dist/components/chat/composer/ComposerShell.d.ts +19 -4
  16. package/dist/components/chat/composer/DraftLifecycle.d.ts +17 -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 +4386 -1074
  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 +3437 -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 +7107 -4252
  40. package/dist/infrastructure.js +1 -1
  41. package/package.json +25 -4
@@ -0,0 +1,238 @@
1
+ "use client";
2
+
3
+ // src/components/chat/composer/document.ts
4
+ function object(value) {
5
+ return value !== null && typeof value === "object" && !Array.isArray(value);
6
+ }
7
+ function keys(value, required, optional = []) {
8
+ return required.every((key) => Object.hasOwn(value, key)) && Object.keys(value).every((key) => required.includes(key) || optional.includes(key));
9
+ }
10
+ function identity(value) {
11
+ return typeof value === "string" && value.length > 0;
12
+ }
13
+ function revision(value) {
14
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
15
+ }
16
+ function copyJson(value, ancestors = new Set) {
17
+ if (value === null || typeof value === "string" || typeof value === "boolean")
18
+ return value;
19
+ if (typeof value === "number" && Number.isFinite(value))
20
+ return value;
21
+ if (typeof value !== "object" || value === null)
22
+ throw new TypeError("Expected JSON data");
23
+ if (ancestors.has(value))
24
+ throw new TypeError("Cyclic data is not portable JSON");
25
+ const prototype = Object.getPrototypeOf(value);
26
+ if (Array.isArray(value) && prototype !== Array.prototype) {
27
+ throw new TypeError("Only plain JSON arrays are supported");
28
+ }
29
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
30
+ throw new TypeError("Only plain JSON objects are supported");
31
+ }
32
+ ancestors.add(value);
33
+ try {
34
+ const descriptors = Object.getOwnPropertyDescriptors(value);
35
+ if (Reflect.ownKeys(value).some((key) => typeof key !== "string"))
36
+ throw new TypeError("Symbol fields are not portable JSON");
37
+ for (const [key, descriptor] of Object.entries(descriptors)) {
38
+ if (Array.isArray(value) && key === "length")
39
+ continue;
40
+ if (!descriptor.enumerable || !("value" in descriptor))
41
+ throw new TypeError("Non-JSON property descriptor");
42
+ }
43
+ if (Array.isArray(value)) {
44
+ if (Object.keys(value).length !== value.length || Object.keys(value).some((key, index) => key !== String(index))) {
45
+ throw new TypeError("Sparse arrays or array properties are not portable JSON");
46
+ }
47
+ const result = [];
48
+ for (let index = 0;index < value.length; index++) {
49
+ result.push(copyJson(descriptors[String(index)].value, ancestors));
50
+ }
51
+ return Object.freeze(result);
52
+ }
53
+ const result = {};
54
+ for (const [key, descriptor] of Object.entries(descriptors)) {
55
+ Object.defineProperty(result, key, {
56
+ value: copyJson(descriptor.value, ancestors),
57
+ enumerable: true
58
+ });
59
+ }
60
+ return Object.freeze(result);
61
+ } finally {
62
+ ancestors.delete(value);
63
+ }
64
+ }
65
+ function snapshotComposerJson(value) {
66
+ return copyJson(value);
67
+ }
68
+ function validScope(value) {
69
+ return value !== undefined && object(value) && keys(value, ["contextKey", "conversationId"]) && identity(value.contextKey) && identity(value.conversationId);
70
+ }
71
+ function validCommand(value) {
72
+ return value !== undefined && object(value) && keys(value, ["providerId", "commandId"]) && identity(value.providerId) && identity(value.commandId);
73
+ }
74
+ function validDocument(value) {
75
+ if (!object(value) || !keys(value, ["schemaVersion", "content"], ["command"]) || value.schemaVersion !== 1 || !Array.isArray(value.content))
76
+ return false;
77
+ if (Object.hasOwn(value, "command") && !validCommand(value.command))
78
+ return false;
79
+ const ids = new Set;
80
+ return value.content.every((node) => {
81
+ if (!object(node))
82
+ return false;
83
+ if (node.type === "text")
84
+ return keys(node, ["type", "text"]) && typeof node.text === "string";
85
+ if (!identity(node.nodeId) || ids.has(node.nodeId))
86
+ return false;
87
+ ids.add(node.nodeId);
88
+ if (node.type === "reference") {
89
+ return keys(node, [
90
+ "type",
91
+ "nodeId",
92
+ "providerId",
93
+ "refId",
94
+ "label",
95
+ "plainText"
96
+ ]) && identity(node.providerId) && identity(node.refId) && typeof node.label === "string" && typeof node.plainText === "string";
97
+ }
98
+ if (node.type === "quote") {
99
+ if (!keys(node, ["type", "nodeId", "text"], ["source"]) || typeof node.text !== "string")
100
+ return false;
101
+ if (!Object.hasOwn(node, "source"))
102
+ return true;
103
+ return node.source !== undefined && object(node.source) && keys(node.source, [], ["providerId", "refId", "label", "messageId", "conversationId"]) && Object.values(node.source).every((field) => typeof field === "string");
104
+ }
105
+ return false;
106
+ });
107
+ }
108
+ function validMetadata(value) {
109
+ return value !== undefined && object(value) && keys(value, ["name", "mediaType", "size"], ["lastModified"]) && typeof value.name === "string" && typeof value.mediaType === "string" && revision(value.size) && (!Object.hasOwn(value, "lastModified") || revision(value.lastModified));
110
+ }
111
+ function validHandle(value) {
112
+ return value !== undefined && object(value) && keys(value, ["providerId", "reference"]) && identity(value.providerId);
113
+ }
114
+ function validAttachments(value, draft) {
115
+ if (!Array.isArray(value))
116
+ return false;
117
+ const ids = new Set;
118
+ return value.every((entry) => {
119
+ if (!object(entry) || !identity(entry.entryId) || ids.has(entry.entryId) || !validMetadata(entry.metadata))
120
+ return false;
121
+ ids.add(entry.entryId);
122
+ if (!draft)
123
+ return keys(entry, ["entryId", "metadata", "handle"]) && validHandle(entry.handle);
124
+ return entry.status === "reattach" ? keys(entry, ["entryId", "metadata", "status"]) : entry.status === "ready" && keys(entry, ["entryId", "metadata", "status", "handle"]) && validHandle(entry.handle);
125
+ });
126
+ }
127
+ function read(input, validate, reason) {
128
+ try {
129
+ const value = copyJson(input);
130
+ if (!validate(value))
131
+ return { status: "incompatible", input, reason };
132
+ return { status: "compatible", value, migrated: false };
133
+ } catch (error) {
134
+ return {
135
+ status: "incompatible",
136
+ input,
137
+ reason: error instanceof Error ? error.message : reason
138
+ };
139
+ }
140
+ }
141
+ function migrateLegacyComposerDocument(text) {
142
+ return Object.freeze({
143
+ schemaVersion: 1,
144
+ content: Object.freeze([Object.freeze({ type: "text", text })])
145
+ });
146
+ }
147
+ function readComposerDocument(input) {
148
+ if (typeof input === "string")
149
+ return {
150
+ status: "compatible",
151
+ value: migrateLegacyComposerDocument(input),
152
+ migrated: true
153
+ };
154
+ return read(input, validDocument, "Unsupported or invalid ComposerDocument v1");
155
+ }
156
+ function snapshotComposerDocument(document) {
157
+ const result = read(document, validDocument, "Unsupported or invalid ComposerDocument v1");
158
+ if (result.status === "incompatible")
159
+ throw new TypeError(result.reason);
160
+ return result.value;
161
+ }
162
+ function readComposerDraft(input, legacy) {
163
+ const migrated = typeof input === "string";
164
+ const candidate = migrated ? {
165
+ draftVersion: 1,
166
+ scope: legacy.scope,
167
+ draftKey: legacy.draftKey,
168
+ revision: 0,
169
+ document: migrateLegacyComposerDocument(input),
170
+ attachments: []
171
+ } : input;
172
+ const result = read(candidate, (value) => object(value) && keys(value, [
173
+ "draftVersion",
174
+ "scope",
175
+ "draftKey",
176
+ "revision",
177
+ "document",
178
+ "attachments"
179
+ ]) && value.draftVersion === 1 && validScope(value.scope) && identity(value.draftKey) && revision(value.revision) && value.document !== undefined && validDocument(value.document) && validAttachments(value.attachments, true), "Unsupported or invalid ComposerDraft v1");
180
+ return result.status === "compatible" ? { ...result, migrated } : { ...result, input };
181
+ }
182
+ function snapshotComposerSubmission(submission) {
183
+ const result = read(submission, (value) => {
184
+ if (!object(value) || !keys(value, [
185
+ "protocolVersion",
186
+ "clientSubmissionId",
187
+ "scope",
188
+ "draftKey",
189
+ "draftRevision",
190
+ "operation",
191
+ "document",
192
+ "attachments",
193
+ "options"
194
+ ], ["intent", "targetTurnId"]) || value.protocolVersion !== 1 || !identity(value.clientSubmissionId) || !validScope(value.scope) || !identity(value.draftKey) || !revision(value.draftRevision) || value.document === undefined || !validDocument(value.document) || !validAttachments(value.attachments, false) || value.options === undefined || !object(value.options))
195
+ return false;
196
+ if (value.operation === "command")
197
+ return object(value.document) && validCommand(value.document.command) && !Object.hasOwn(value, "intent") && !Object.hasOwn(value, "targetTurnId");
198
+ if (value.operation !== "prompt")
199
+ return false;
200
+ return value.intent === "steer" ? identity(value.targetTurnId) : (value.intent === "send" || value.intent === "follow_up") && !Object.hasOwn(value, "targetTurnId");
201
+ }, "Unsupported or invalid ComposerSubmission v1");
202
+ if (result.status === "incompatible")
203
+ throw new TypeError(result.reason);
204
+ return result.value;
205
+ }
206
+ function exportComposerText(document) {
207
+ const snapshot = snapshotComposerDocument(document);
208
+ let output = "";
209
+ let afterQuote = false;
210
+ for (const node of snapshot.content) {
211
+ const text = node.type === "reference" ? node.plainText : node.text;
212
+ if (node.type === "quote") {
213
+ if (output && !output.endsWith(`
214
+ `))
215
+ output += `
216
+ `;
217
+ output += text.split(/\r\n|\r|\n/).map((line) => `> ${line}`).join(`
218
+ `);
219
+ if (node.source?.label) {
220
+ output += `
221
+ ` + node.source.label.split(/\r\n|\r|\n/).map((line, index) => `> ${index === 0 ? "— " : ""}${line}`).join(`
222
+ `);
223
+ }
224
+ afterQuote = true;
225
+ } else {
226
+ if (afterQuote && text && !text.startsWith(`
227
+ `) && !text.startsWith("\r"))
228
+ output += `
229
+ `;
230
+ output += text;
231
+ if (text)
232
+ afterQuote = false;
233
+ }
234
+ }
235
+ return output;
236
+ }
237
+
238
+ export { snapshotComposerJson, migrateLegacyComposerDocument, readComposerDocument, snapshotComposerDocument, readComposerDraft, snapshotComposerSubmission, exportComposerText };
@@ -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" */
@@ -101,6 +105,7 @@ export interface ChatComposerCompletion {
101
105
  label: string;
102
106
  description?: ReactNode;
103
107
  disabled?: boolean;
108
+ group?: string;
104
109
  }
105
110
  export interface ChatComposerCompletionContext {
106
111
  value: string;
@@ -136,6 +141,9 @@ export interface ChatComposerProps extends Omit<ComponentProps<"div">, "children
136
141
  /** Enables the native file picker and attachment removal controls. */
137
142
  onAttachmentsChange?: (files: File[]) => void;
138
143
  accept?: string;
144
+ /** Shared validation for picker, pasted files, and dropped files. */
145
+ attachmentPolicy?: ComposerAttachmentIntakePolicy;
146
+ onAttachmentRejected?: (rejected: readonly ComposerAttachmentRejection[]) => void;
139
147
  /** @default true */
140
148
  multiple?: boolean;
141
149
  /** Permit a draft containing only files. @default false */
@@ -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,42 @@
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
+ readonly onStop?: () => void;
30
+ readonly label?: string;
31
+ readonly attachLabel?: string;
32
+ readonly stopLabel?: string;
33
+ readonly minRows?: number;
34
+ readonly maxRows?: number;
35
+ readonly error?: ReactNode;
36
+ readonly children?: ReactNode;
37
+ }
38
+ /** The rich and semantic plain adapters expose the same editor-independent API. */
39
+ export type ChatSessionComposerHandle = ComposerEditorHandle;
40
+ /** Final R0 public name: RichChatComposer, exported only at /chat/rich. */
41
+ export type RichChatComposerProps = ChatSessionComposerProps;
42
+ 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,66 @@
1
+ import type { ComposerDocument, ComposerError, ComposerProvider, ComposerProviderAction, ComposerProviderCandidate, ComposerProviderRequest, ComposerProviderResult, ComposerScope } from "./Composer.types";
2
+ export interface ComposerProviderBreadcrumb {
3
+ readonly refId: string;
4
+ readonly label: string;
5
+ }
6
+ /** Runtime navigation context; it does not change the portable request schema. */
7
+ export interface ComposerProviderNavigation {
8
+ readonly breadcrumbs: readonly ComposerProviderBreadcrumb[];
9
+ readonly refId?: string;
10
+ }
11
+ export interface ComposerCompletionProvider extends ComposerProvider {
12
+ readonly label?: string;
13
+ /** Commands and editable skills can share a marker with distinct providers. */
14
+ readonly trigger: {
15
+ readonly text: string;
16
+ readonly position: "leading" | "word";
17
+ };
18
+ readonly query: (request: ComposerProviderRequest, signal: AbortSignal, navigation?: ComposerProviderNavigation) => Promise<ComposerProviderResult>;
19
+ }
20
+ /** UTF-16 offsets in one semantic text node. A range selection closes suggestions. */
21
+ export interface ComposerProviderSelection {
22
+ readonly nodeIndex: number;
23
+ readonly start: number;
24
+ readonly end: number;
25
+ }
26
+ export interface ComposerProviderContext {
27
+ readonly document: ComposerDocument;
28
+ readonly documentRevision: number;
29
+ readonly scope: ComposerScope;
30
+ readonly instanceGeneration: number;
31
+ readonly selection: ComposerProviderSelection | null;
32
+ readonly providers: readonly ComposerCompletionProvider[];
33
+ /** Adapter/host availability, independent of a provider's own disabled reason. */
34
+ readonly candidateDisabledReason?: (candidate: ComposerProviderCandidate) => string | undefined;
35
+ }
36
+ export interface ComposerProviderItem {
37
+ /** Stable, DOM-safe identity derived from providerId and candidate.id. */
38
+ readonly id: string;
39
+ readonly providerId: string;
40
+ readonly candidate: ComposerProviderCandidate;
41
+ readonly request: ComposerProviderRequest;
42
+ }
43
+ export type ComposerProviderStatus = "idle" | "loading" | "ready" | "empty" | "error";
44
+ export interface ComposerProviderGroup {
45
+ readonly providerId: string;
46
+ readonly label: string;
47
+ readonly status: Exclude<ComposerProviderStatus, "idle">;
48
+ readonly items: readonly ComposerProviderItem[];
49
+ readonly request: ComposerProviderRequest;
50
+ readonly error?: ComposerError;
51
+ }
52
+ export interface ComposerProviderSnapshot {
53
+ readonly status: ComposerProviderStatus;
54
+ readonly groups: readonly ComposerProviderGroup[];
55
+ readonly items: readonly ComposerProviderItem[];
56
+ readonly activeId?: string;
57
+ readonly breadcrumbs: readonly ComposerProviderBreadcrumb[];
58
+ readonly error?: ComposerError;
59
+ }
60
+ /** Apply this action once, in the adapter transaction for the captured request. */
61
+ export interface ComposerProviderSelectionEffect {
62
+ readonly itemId: string;
63
+ readonly request: ComposerProviderRequest;
64
+ readonly candidate: ComposerProviderCandidate;
65
+ readonly action: ComposerProviderAction;
66
+ }
@@ -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
+ }