@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.
- package/README.md +111 -4
- package/dist/chunk-kg46s2vk.js +238 -0
- package/dist/chunk-rd10x4gc.js +733 -0
- package/dist/components/chat/Chat.types.d.ts +15 -0
- package/dist/components/chat/ChatAuthoritativeQueue.d.ts +4 -0
- package/dist/components/chat/ChatSessionComposer.d.ts +4 -0
- package/dist/components/chat/ChatSessionComposer.types.d.ts +46 -0
- package/dist/components/chat/ComposerAttachment.types.d.ts +80 -0
- package/dist/components/chat/ComposerDraft.types.d.ts +89 -0
- package/dist/components/chat/ComposerProvider.types.d.ts +70 -0
- package/dist/components/chat/ComposerQueue.types.d.ts +64 -0
- package/dist/components/chat/ComposerSession.types.d.ts +78 -0
- package/dist/components/chat/ComposerSettings.d.ts +4 -0
- package/dist/components/chat/composer/CompletionList.d.ts +15 -0
- package/dist/components/chat/composer/ComposerShell.d.ts +23 -4
- package/dist/components/chat/composer/DraftLifecycle.d.ts +19 -0
- package/dist/components/chat/composer/EditorAdapter.types.d.ts +36 -0
- package/dist/components/chat/composer/PlainEditor.d.ts +2 -0
- package/dist/components/chat/composer/PlainSemanticEditor.d.ts +6 -0
- package/dist/components/chat/composer/PreservedDraft.d.ts +7 -0
- package/dist/components/chat/composer/SemanticComposer.d.ts +10 -0
- package/dist/components/chat/composer/attachments.d.ts +4 -0
- package/dist/components/chat/composer/document.d.ts +3 -1
- package/dist/components/chat/composer/drafts.d.ts +2 -0
- package/dist/components/chat/composer/providers.d.ts +40 -0
- package/dist/components/chat/composer/session.d.ts +30 -0
- package/dist/components/chat/composer/useComposerAttachments.d.ts +3 -0
- package/dist/components/chat/composer/useComposerDraft.d.ts +3 -0
- package/dist/components/chat/composer/useComposerProviders.d.ts +7 -0
- package/dist/components/chat/composer/useComposerSession.d.ts +16 -0
- package/dist/components/chat/index.d.ts +17 -0
- package/dist/components/chat/index.js +4765 -1286
- package/dist/components/chat/rich/LexicalEditor.d.ts +10 -0
- package/dist/components/chat/rich/RichChatComposer.d.ts +4 -0
- package/dist/components/chat/rich/index.d.ts +2 -0
- package/dist/components/chat/rich/index.js +3478 -0
- package/dist/components/chat/rich/nodes.d.ts +49 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/index.js +11994 -8740
- package/dist/infrastructure.js +1 -1
- package/dist/styles.css +180 -2
- package/package.json +27 -6
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ 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. The package now requires Core 1.21.
|
|
73
|
+
accessible expansion and focus cleanup. The package now requires Core 1.21.1,
|
|
74
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
|
|
@@ -92,6 +92,22 @@ repositories or conversations: a late acceptance or error from the previous
|
|
|
92
92
|
scope cannot clear the current draft or call its error handler. Pending admission
|
|
93
93
|
leaves editing available. The host still owns the controlled draft and files.
|
|
94
94
|
|
|
95
|
+
Composer actions use icon buttons with accessible names and `title` hints in both
|
|
96
|
+
layouts. `attachLabel`, `sendLabel` and `stopLabel` customize those names and hints.
|
|
97
|
+
Attachment retry/cancel/remove and default queue actions follow the same pattern.
|
|
98
|
+
The shared composer padding is 0.5rem.
|
|
99
|
+
|
|
100
|
+
Set `compact` on `Chat.Composer`, `ChatSessionComposer` or `RichChatComposer`
|
|
101
|
+
for a compact toolbar with accessible icon buttons and a horizontal strip of
|
|
102
|
+
simple ready-image thumbnails. Mixed files, preparation, errors and custom
|
|
103
|
+
attachment renderers retain full rows. The default wrapping layout remains
|
|
104
|
+
available. Compose host-owned settings through `children`, using Core's native
|
|
105
|
+
`popover chat-composer-menu` classes when a configuration menu is needed.
|
|
106
|
+
The compact `+` opens a native Add menu for files, explicit draft save/reload
|
|
107
|
+
and optional `addMenu` content. Routine save/admission status is announced without
|
|
108
|
+
adding rows. Its primary button sends an eligible draft or stops the running turn
|
|
109
|
+
when submission is unavailable; the default layout retains separate controls.
|
|
110
|
+
|
|
95
111
|
Root and `/chat` exports also provide editor-independent `ComposerDocument`,
|
|
96
112
|
`ComposerDraft`, submission/receipt, provider, attachment and queue types.
|
|
97
113
|
`readComposerDocument` and `readComposerDraft` preserve incompatible input for
|
|
@@ -100,10 +116,101 @@ copy and freeze portable JSON. `exportComposerText` and `exportComposerMarkdown`
|
|
|
100
116
|
project references through `plainText` and retain quote attribution. Invalid
|
|
101
117
|
snapshots throw instead of silently discarding unsupported fields. Portable
|
|
102
118
|
examples are published at `@duskmoon-dev/components/chat/contracts.v1.json`.
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
`ChatSessionComposer` uses those contracts with a controlled semantic document,
|
|
120
|
+
application-owned `ComposerSessionHost`, scope and draft key. The original
|
|
121
|
+
string/File-based `Chat.Composer` remains available with its existing ref and
|
|
122
|
+
callbacks. The optional editor is imported separately:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import { useState } from "react";
|
|
126
|
+
import type {
|
|
127
|
+
ComposerDocumentUpdate,
|
|
128
|
+
ComposerScope,
|
|
129
|
+
ComposerSessionHost,
|
|
130
|
+
} from "@duskmoon-dev/components/chat";
|
|
131
|
+
import { RichChatComposer } from "@duskmoon-dev/components/chat/rich";
|
|
132
|
+
|
|
133
|
+
export function PromptBox({
|
|
134
|
+
host,
|
|
135
|
+
scope,
|
|
136
|
+
}: {
|
|
137
|
+
host: ComposerSessionHost;
|
|
138
|
+
scope: ComposerScope;
|
|
139
|
+
}) {
|
|
140
|
+
const [value, setValue] = useState<ComposerDocumentUpdate>({
|
|
141
|
+
document: { schemaVersion: 1, content: [{ type: "text", text: "" }] },
|
|
142
|
+
revision: 0,
|
|
143
|
+
origin: "replace",
|
|
144
|
+
originId: "initial-draft",
|
|
145
|
+
});
|
|
146
|
+
return (
|
|
147
|
+
<RichChatComposer
|
|
148
|
+
value={value}
|
|
149
|
+
onDocumentChange={setValue}
|
|
150
|
+
scope={scope}
|
|
151
|
+
draftKey="main-prompt"
|
|
152
|
+
host={host}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
105
157
|
|
|
106
|
-
|
|
158
|
+
Use `ChatSessionComposer` from root or `/chat` with the same props for text-only
|
|
159
|
+
semantic drafts. RichChatComposer is available only from `/chat/rich`. Keep a
|
|
160
|
+
single compatible Lexical runtime in consumers that also import Lexical directly;
|
|
161
|
+
ordinary root and `/chat` imports do not initialize it.
|
|
162
|
+
|
|
163
|
+
Echo each `onDocumentChange` update unchanged. The rich editor retains selection
|
|
164
|
+
and undo for echoes; explicit replace, restore, scope switch and clear operations
|
|
165
|
+
reset its history. Remounts restore semantic content, not undo history. Its ref
|
|
166
|
+
inserts references, quotes, text and claimed commands without exposing Lexical.
|
|
167
|
+
References and quotes are atomic. Claimed command identity stays distinct from
|
|
168
|
+
editable skill text. Rich copy/cut includes portable semantic content and plain
|
|
169
|
+
text; rich paste creates fresh occurrence IDs, while external paste uses plain
|
|
170
|
+
text. Mixed file/text paste preserves text and validates files through the shared
|
|
171
|
+
picker/paste/drop policy. Unsupported content is retained for recovery rather
|
|
172
|
+
than silently flattened if the editor cannot load or a draft is incompatible.
|
|
173
|
+
|
|
174
|
+
Keep `host.recovery = createComposerRecoveryOwner()` outside the editor's mount
|
|
175
|
+
lifetime. Pending and unknown attempts retain the exact immutable submission
|
|
176
|
+
snapshot and ID. An accepted prompt reports actual delivery and persistence;
|
|
177
|
+
an accepted command returns a result without claiming a queued prompt or turn.
|
|
178
|
+
Unknown outcomes preserve the draft: reconcile using `host.reconcile` before any
|
|
179
|
+
explicit `host.authorizeRetry` of the same snapshot. Admission is not completed
|
|
180
|
+
generation. Stop is a separate `onStop` action and remains available while file
|
|
181
|
+
preparation or admission is pending. Host capabilities determine which active-turn
|
|
182
|
+
intents and controls are available.
|
|
183
|
+
|
|
184
|
+
Optional `attachmentOptions` validates and prepares each file occurrence, with
|
|
185
|
+
cancellation, progress, failure and retry. Only ready portable handles enter a
|
|
186
|
+
submission; runtime `File` objects and preview URLs stay out of saved documents.
|
|
187
|
+
Recovered files require reattachment unless the host explicitly confirms handle
|
|
188
|
+
recovery. A stable optional `draftAdapter` loads scoped drafts and supports explicit
|
|
189
|
+
Save draft; storage durability, retention and coordination with other writers
|
|
190
|
+
belong to the application. The UI never automatically overwrites incompatible
|
|
191
|
+
stored content.
|
|
192
|
+
|
|
193
|
+
`providers` supply scoped asynchronous candidates, disabled reasons, directory
|
|
194
|
+
drill-down and insert/invoke actions. In compact mode, results open in a native
|
|
195
|
+
popover above the composer, with grouped rows, keyboard navigation, filtering and
|
|
196
|
+
native dismissal. Optional provider `icon` and `sourceLabel` decorate the rows;
|
|
197
|
+
they never enter portable documents or submissions. Use a leading `/` provider
|
|
198
|
+
for skills and commands: skills insert editable instructions, rich claimed
|
|
199
|
+
commands retain their identity until submission, and `invoke` actions call
|
|
200
|
+
`onProviderInvoke` independently. The plain editor supports text skills and host
|
|
201
|
+
invocation; claimed commands require the rich editor.
|
|
202
|
+
The host resolves and authorizes references,
|
|
203
|
+
quote provenance, commands and attachment handles; portable validity is not
|
|
204
|
+
authorization. `ChatAuthoritativeQueue` renders confirmed projections and requests
|
|
205
|
+
revision-checked edit/remove/promote mutations. Apply canonical projections through
|
|
206
|
+
`onProjection`; an optimistic click does not confirm membership or order.
|
|
207
|
+
`ComposerSettings` likewise keeps values controlled until the host acknowledges
|
|
208
|
+
and applies a request. The host owns transport, model execution, uploads,
|
|
209
|
+
idempotency, persistence and execution policy. The Chat documentation includes
|
|
210
|
+
interactive fake-host examples with real local state transitions; their memory
|
|
211
|
+
storage survives editor remounts only and makes no durable delivery claim.
|
|
212
|
+
|
|
213
|
+
Core 1.21.1 still has a known Moonlight contrast gap for neutral outlined/ghost
|
|
107
214
|
labels ([duskmoonui#78](https://github.com/duskmoon-dev/duskmoonui/issues/78)).
|
|
108
215
|
The upstream fix is required before claiming complete palette accessibility.
|
|
109
216
|
|
|
@@ -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 };
|