@norio-office/rich-text 0.7.1 → 0.8.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.
- package/README.md +895 -824
- package/dist/ai/bridge.d.ts +335 -0
- package/dist/ai/consume-stream.d.ts +8 -0
- package/dist/ai/executor.d.ts +19 -0
- package/dist/ai/index.d.ts +8 -0
- package/dist/ai/index.js +4106 -0
- package/dist/ai/tools.d.ts +158 -0
- package/dist/ai-protocol/index.d.ts +12 -0
- package/dist/ai-protocol/index.js +2372 -0
- package/dist/ai-protocol/json-schema.d.ts +5 -0
- package/dist/ai-protocol/patch.d.ts +77 -0
- package/dist/ai-protocol/references.d.ts +11 -0
- package/dist/ai-protocol/stream.d.ts +94 -0
- package/dist/ai-protocol/tools.d.ts +8 -0
- package/dist/ai-protocol/validation.d.ts +20 -0
- package/dist/components/RichTextEditor.vue.d.ts +11 -4
- package/dist/document/ai-identity.d.ts +4 -0
- package/dist/document/nodes/columns-block.d.ts +2 -0
- package/dist/document/nodes/countdown-block.d.ts +2 -0
- package/dist/document/nodes/formula-block.d.ts +2 -0
- package/dist/document/nodes/highlight-block.d.ts +2 -0
- package/dist/document/nodes/image-block.d.ts +8 -0
- package/dist/document/nodes/link-block.d.ts +2 -0
- package/dist/document/nodes/local-file-block.d.ts +2 -0
- package/dist/document/nodes/mention.d.ts +2 -0
- package/dist/document/nodes/office-code-block.d.ts +1 -0
- package/dist/document/nodes/table-cells.d.ts +2 -0
- package/dist/document/nodes/themed-table.d.ts +1 -0
- package/dist/document/nodes/video-block.d.ts +8 -0
- package/dist/document/schema.d.ts +17 -0
- package/dist/extensions/ai-identity.d.ts +1 -0
- package/dist/extensions/columns-block.d.ts +1 -2
- package/dist/extensions/countdown-block.d.ts +1 -2
- package/dist/extensions/formula-block.d.ts +1 -2
- package/dist/extensions/highlight-block.d.ts +1 -2
- package/dist/extensions/image-block.d.ts +4 -8
- package/dist/extensions/link-block.d.ts +1 -2
- package/dist/extensions/local-file-block.d.ts +1 -2
- package/dist/extensions/mention.d.ts +1 -2
- package/dist/extensions/video-block.d.ts +4 -8
- package/dist/{html2canvas-4hiP1s1t.js → html2canvas-BnDzIoab.js} +112 -126
- package/dist/index.js +8343 -7407
- package/dist/index.umd.cjs +2196 -1995
- package/dist/nordox/index.d.ts +95 -0
- package/dist/nordox/index.js +2094 -0
- package/dist/{chunk-C_CI6nMA.js → rolldown-runtime-VHNaYcLd.js} +3 -3
- package/dist/style.css +1 -1
- package/dist/types.d.ts +9 -1
- package/docs/ai/README.md +108 -0
- package/docs/ai/acceptance-report.md +88 -0
- package/docs/ai/capability-matrix.md +43 -0
- package/docs/ai/compatibility.md +9 -0
- package/docs/icons.md +21 -0
- package/examples/ai/browser/App.vue +151 -0
- package/examples/ai/browser/index.html +12 -0
- package/examples/ai/browser/main.ts +5 -0
- package/examples/ai/browser/tsconfig.json +7 -0
- package/examples/ai/browser/vite.config.ts +14 -0
- package/examples/ai/node.mjs +28 -0
- package/package.json +15 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { Editor, JSONContent } from '@tiptap/core';
|
|
2
|
+
import { RichTextStreamEvent, RichTextStreamMode } from '../ai-protocol/stream';
|
|
3
|
+
import { RichTextPatchOperation } from '../ai-protocol/patch';
|
|
4
|
+
import { RichTextExternalReference } from '../ai-protocol/references';
|
|
5
|
+
import { NordoxResourceResolver, RichTextAssetPackaging } from '../nordox';
|
|
6
|
+
export type RichTextAiTargetClearReason = 'content-click' | 'host-close' | 'badge-close' | 'commit' | 'invalidated' | 'dispose' | 'document-changed' | 'mode-changed';
|
|
7
|
+
export type RichTextAiTargetControls = {
|
|
8
|
+
select(): void;
|
|
9
|
+
clear(reason: RichTextAiTargetClearReason): void;
|
|
10
|
+
};
|
|
11
|
+
export type RichTextAiEditorAdapter = {
|
|
12
|
+
getEditor(): Editor | null;
|
|
13
|
+
isCollaborationConfigured(): boolean;
|
|
14
|
+
getSelectedBlocks(): Array<{
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
nodeId?: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
bindAiTargetControls?(controls: RichTextAiTargetControls | null): void;
|
|
20
|
+
setAiTargetUiState?(state: {
|
|
21
|
+
active: boolean;
|
|
22
|
+
busy: boolean;
|
|
23
|
+
available: boolean;
|
|
24
|
+
reason: string;
|
|
25
|
+
}): void;
|
|
26
|
+
};
|
|
27
|
+
export type RichTextAiEditorInstance = {
|
|
28
|
+
getAiAdapter(): RichTextAiEditorAdapter;
|
|
29
|
+
};
|
|
30
|
+
export type RichTextAiPolicy = {
|
|
31
|
+
allowWholeDocument?: boolean;
|
|
32
|
+
allowedOperations?: RichTextPatchOperation['type'][];
|
|
33
|
+
contextTtlMs?: number;
|
|
34
|
+
maxReadCharacters?: number;
|
|
35
|
+
};
|
|
36
|
+
export type RichTextAiWritePolicy = {
|
|
37
|
+
allowedOperations?: RichTextPatchOperation['type'][];
|
|
38
|
+
allowedMarkAttributes?: Record<string, string[]>;
|
|
39
|
+
allowedNodeAttributes?: Record<string, string[]>;
|
|
40
|
+
allowedTableActions?: Array<Extract<RichTextPatchOperation, {
|
|
41
|
+
type: 'tableOperation';
|
|
42
|
+
}>['action']>;
|
|
43
|
+
};
|
|
44
|
+
export type RichTextAiBridgeOptions = {
|
|
45
|
+
documentId: string;
|
|
46
|
+
policy?: RichTextAiPolicy;
|
|
47
|
+
resourceResolver?: NordoxResourceResolver;
|
|
48
|
+
assetPackaging?: RichTextAssetPackaging;
|
|
49
|
+
authorizeExternalReference?: (reference: RichTextExternalReference) => boolean;
|
|
50
|
+
};
|
|
51
|
+
export type RichTextAiSelectionSnapshot = {
|
|
52
|
+
kind: 'cursor' | 'textRange' | 'node' | 'blockSet' | 'tableCells' | 'none';
|
|
53
|
+
from?: number;
|
|
54
|
+
to?: number;
|
|
55
|
+
text?: string;
|
|
56
|
+
direction?: 'forward' | 'backward';
|
|
57
|
+
markRanges?: Array<{
|
|
58
|
+
from: number;
|
|
59
|
+
to: number;
|
|
60
|
+
marks: JSONContent['marks'];
|
|
61
|
+
}>;
|
|
62
|
+
node?: JSONContent;
|
|
63
|
+
blocks?: Array<{
|
|
64
|
+
from: number;
|
|
65
|
+
to: number;
|
|
66
|
+
nodeId?: string | null;
|
|
67
|
+
}>;
|
|
68
|
+
cells?: Array<{
|
|
69
|
+
from: number;
|
|
70
|
+
to: number;
|
|
71
|
+
nodeId?: string | null;
|
|
72
|
+
row?: number;
|
|
73
|
+
column?: number;
|
|
74
|
+
}>;
|
|
75
|
+
tableId?: string | null;
|
|
76
|
+
anchorCell?: number;
|
|
77
|
+
headCell?: number;
|
|
78
|
+
revision: number;
|
|
79
|
+
};
|
|
80
|
+
export type RichTextAiTarget = {
|
|
81
|
+
targetId: string;
|
|
82
|
+
documentId: string;
|
|
83
|
+
editorSessionId: string;
|
|
84
|
+
revision: number;
|
|
85
|
+
selection: RichTextAiSelectionSnapshot;
|
|
86
|
+
summary: string;
|
|
87
|
+
previewText: string;
|
|
88
|
+
previewTruncated: boolean;
|
|
89
|
+
content: JSONContent[];
|
|
90
|
+
};
|
|
91
|
+
export type RichTextAiBridgeEvent = {
|
|
92
|
+
type: 'change';
|
|
93
|
+
source: 'ai' | 'user';
|
|
94
|
+
revision: number;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'applied';
|
|
97
|
+
requestId: string;
|
|
98
|
+
previousRevision: number;
|
|
99
|
+
revision: number;
|
|
100
|
+
changed: boolean;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'stream-preview';
|
|
103
|
+
streamId: string;
|
|
104
|
+
committed: false;
|
|
105
|
+
seq: number;
|
|
106
|
+
} | {
|
|
107
|
+
type: 'stream-discarded';
|
|
108
|
+
streamId: string;
|
|
109
|
+
reason?: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'ai-target-change';
|
|
112
|
+
target: RichTextAiTarget | null;
|
|
113
|
+
reason: 'select' | 'replace' | RichTextAiTargetClearReason;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'ai-target-invalidated';
|
|
116
|
+
targetId: string;
|
|
117
|
+
reason: 'target-changed' | 'target-deleted' | 'document-changed';
|
|
118
|
+
};
|
|
119
|
+
export type RichTextAiApplyResult = {
|
|
120
|
+
requestId: string;
|
|
121
|
+
previousRevision: number;
|
|
122
|
+
revision: number;
|
|
123
|
+
changed: boolean;
|
|
124
|
+
targetRefs: string[];
|
|
125
|
+
};
|
|
126
|
+
export declare class RichTextAiBridgeError extends Error {
|
|
127
|
+
readonly code: string;
|
|
128
|
+
readonly retryable: boolean;
|
|
129
|
+
constructor(code: string, message: string, retryable?: boolean);
|
|
130
|
+
}
|
|
131
|
+
export declare function createRichTextAiBridge(instance: RichTextAiEditorInstance, options: RichTextAiBridgeOptions): {
|
|
132
|
+
getCapabilities: () => {
|
|
133
|
+
schemaVersion: string;
|
|
134
|
+
protocolVersion: number;
|
|
135
|
+
streamProtocolVersion: number;
|
|
136
|
+
documentId: string;
|
|
137
|
+
mode: "preview" | "edit";
|
|
138
|
+
collaboration: boolean;
|
|
139
|
+
nodes: string[];
|
|
140
|
+
marks: string[];
|
|
141
|
+
nodeAttributes: {
|
|
142
|
+
[k: string]: {
|
|
143
|
+
[k: string]: {
|
|
144
|
+
default: {} | null;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
markAttributes: {
|
|
149
|
+
[k: string]: {
|
|
150
|
+
[k: string]: {
|
|
151
|
+
default: {} | null;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
nodeAttributeConstraints: {
|
|
156
|
+
[k: string]: Record<string, unknown>;
|
|
157
|
+
};
|
|
158
|
+
markAttributeConstraints: {
|
|
159
|
+
[k: string]: Record<string, unknown>;
|
|
160
|
+
};
|
|
161
|
+
nodeContentRules: {
|
|
162
|
+
[k: string]: {
|
|
163
|
+
content: string | null;
|
|
164
|
+
marks: string | null;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
targetKinds: readonly ["cursor", "textRange", "node", "blockSet", "tableCells", "none"];
|
|
168
|
+
externalDependencies: {
|
|
169
|
+
authorizationConfigured: boolean;
|
|
170
|
+
byteResolverConfigured: boolean;
|
|
171
|
+
media: string;
|
|
172
|
+
mentions: string;
|
|
173
|
+
comments: string;
|
|
174
|
+
embedding: string;
|
|
175
|
+
};
|
|
176
|
+
resourcePackaging: {
|
|
177
|
+
images: string[];
|
|
178
|
+
videos: string[];
|
|
179
|
+
files: string[];
|
|
180
|
+
};
|
|
181
|
+
operations: ("insertContent" | "replaceText" | "replaceFragment" | "setMarks" | "unsetMarks" | "setNodeAttributes" | "unsetNodeAttributes" | "deleteContent" | "moveBlocks" | "transformBlocks" | "tableOperation")[];
|
|
182
|
+
streamModes: string[];
|
|
183
|
+
streamEvents: string[];
|
|
184
|
+
streamLimits: import('../ai-protocol').RichTextStreamLimits;
|
|
185
|
+
streamPreview: {
|
|
186
|
+
localOnly: boolean;
|
|
187
|
+
committedDocumentUnchangedUntilCommit: boolean;
|
|
188
|
+
};
|
|
189
|
+
commitSemantics: string;
|
|
190
|
+
};
|
|
191
|
+
getDocumentSnapshot: () => {
|
|
192
|
+
documentId: string;
|
|
193
|
+
revision: number;
|
|
194
|
+
schemaVersion: string;
|
|
195
|
+
document: import('@tiptap/core').DocumentType<Record<string, any> | undefined, import('@tiptap/core').NodeType<string, Record<string, any> | undefined, any, (import('@tiptap/core').NodeType<any, any, any, any> | import('@tiptap/core').TextType<import('@tiptap/core').MarkType<any, any>>)[]>[]>;
|
|
196
|
+
text: string;
|
|
197
|
+
};
|
|
198
|
+
captureSelection: () => RichTextAiSelectionSnapshot;
|
|
199
|
+
selectAiTarget: () => RichTextAiTarget;
|
|
200
|
+
getAiTarget: () => RichTextAiTarget | null;
|
|
201
|
+
clearAiTarget: (input?: {
|
|
202
|
+
targetId?: string;
|
|
203
|
+
reason?: RichTextAiTargetClearReason;
|
|
204
|
+
}) => boolean;
|
|
205
|
+
createEditContext: (input: {
|
|
206
|
+
requestId: string;
|
|
207
|
+
instruction: string;
|
|
208
|
+
scope?: "selection" | "document";
|
|
209
|
+
targetId?: string;
|
|
210
|
+
includeDescendants?: boolean;
|
|
211
|
+
additionalBlocks?: Array<{
|
|
212
|
+
from: number;
|
|
213
|
+
to: number;
|
|
214
|
+
nodeId?: string | null;
|
|
215
|
+
}>;
|
|
216
|
+
writePolicy?: RichTextAiWritePolicy;
|
|
217
|
+
}) => {
|
|
218
|
+
contextId: `${string}-${string}-${string}-${string}-${string}`;
|
|
219
|
+
documentId: string;
|
|
220
|
+
requestId: string;
|
|
221
|
+
baseRevision: number;
|
|
222
|
+
expiresAt: number;
|
|
223
|
+
selection: RichTextAiSelectionSnapshot;
|
|
224
|
+
targetRefs: string[];
|
|
225
|
+
};
|
|
226
|
+
getContextSelection: (contextId: string) => RichTextAiSelectionSnapshot;
|
|
227
|
+
getOutline: (input: {
|
|
228
|
+
contextId: string;
|
|
229
|
+
limit?: number;
|
|
230
|
+
}) => {
|
|
231
|
+
documentId: string;
|
|
232
|
+
revision: number;
|
|
233
|
+
blocks: {
|
|
234
|
+
aiId: string | null;
|
|
235
|
+
nodeType: string;
|
|
236
|
+
level: number | null;
|
|
237
|
+
text: string;
|
|
238
|
+
}[];
|
|
239
|
+
truncated: boolean;
|
|
240
|
+
};
|
|
241
|
+
readContent: (input: {
|
|
242
|
+
contextId: string;
|
|
243
|
+
targetRefs?: string[];
|
|
244
|
+
budget?: number;
|
|
245
|
+
cursor?: string;
|
|
246
|
+
includeNeighbors?: boolean;
|
|
247
|
+
}) => {
|
|
248
|
+
documentId: string;
|
|
249
|
+
revision: number;
|
|
250
|
+
results: {
|
|
251
|
+
text: string;
|
|
252
|
+
truncated: boolean;
|
|
253
|
+
content: any;
|
|
254
|
+
nextCursor: string | null;
|
|
255
|
+
neighbors: {
|
|
256
|
+
before: string;
|
|
257
|
+
after: string;
|
|
258
|
+
} | undefined;
|
|
259
|
+
nodeType: string | undefined;
|
|
260
|
+
parentRef: string | undefined;
|
|
261
|
+
tableRow: number | undefined;
|
|
262
|
+
tableColumn: number | undefined;
|
|
263
|
+
isHeader: boolean | undefined;
|
|
264
|
+
operations: ("insertContent" | "replaceText" | "replaceFragment" | "setMarks" | "unsetMarks" | "setNodeAttributes" | "unsetNodeAttributes" | "deleteContent" | "moveBlocks" | "transformBlocks" | "tableOperation")[];
|
|
265
|
+
tableActions: ("deleteColumn" | "deleteRow" | "mergeCells" | "splitCell" | "insertRowBefore" | "insertRowAfter" | "insertColumnBefore" | "insertColumnAfter" | "setCellContent" | "setCellBackground" | "setTableTheme")[];
|
|
266
|
+
targetRef: string;
|
|
267
|
+
kind: "cursor" | "document" | "node" | "textRange" | "blockSet" | "tableCells";
|
|
268
|
+
}[];
|
|
269
|
+
truncated: boolean;
|
|
270
|
+
};
|
|
271
|
+
validatePatch: (input: {
|
|
272
|
+
contextId: string;
|
|
273
|
+
patch: unknown;
|
|
274
|
+
}) => {
|
|
275
|
+
valid: true;
|
|
276
|
+
changed: boolean;
|
|
277
|
+
revision: number;
|
|
278
|
+
};
|
|
279
|
+
previewPatch: (input: {
|
|
280
|
+
contextId: string;
|
|
281
|
+
patch: unknown;
|
|
282
|
+
}) => {
|
|
283
|
+
committed: false;
|
|
284
|
+
changed: boolean;
|
|
285
|
+
document: any;
|
|
286
|
+
revision: number;
|
|
287
|
+
};
|
|
288
|
+
applyPatch: (input: {
|
|
289
|
+
contextId: string;
|
|
290
|
+
patch: unknown;
|
|
291
|
+
}, clearTargetAfterCommit?: boolean) => RichTextAiApplyResult;
|
|
292
|
+
beginStream: (input: {
|
|
293
|
+
contextId: string;
|
|
294
|
+
requestId: string;
|
|
295
|
+
mode: RichTextStreamMode;
|
|
296
|
+
targetRef: string;
|
|
297
|
+
}) => {
|
|
298
|
+
streamId: `${string}-${string}-${string}-${string}-${string}`;
|
|
299
|
+
};
|
|
300
|
+
appendStreamEvent: (input: {
|
|
301
|
+
streamId: string;
|
|
302
|
+
event: RichTextStreamEvent;
|
|
303
|
+
}) => {
|
|
304
|
+
committed: false;
|
|
305
|
+
streamId: string;
|
|
306
|
+
seq: number;
|
|
307
|
+
ended: boolean;
|
|
308
|
+
};
|
|
309
|
+
getStreamSnapshot: (id: string) => {
|
|
310
|
+
committed: false;
|
|
311
|
+
streamId: string;
|
|
312
|
+
mode: RichTextStreamMode;
|
|
313
|
+
seq: number;
|
|
314
|
+
ended: boolean;
|
|
315
|
+
nodes: JSONContent[];
|
|
316
|
+
openNodes: JSONContent[];
|
|
317
|
+
replacementText: string;
|
|
318
|
+
operations: Record<string, unknown>[];
|
|
319
|
+
};
|
|
320
|
+
commitStream: (input: {
|
|
321
|
+
streamId: string;
|
|
322
|
+
signal?: AbortSignal;
|
|
323
|
+
}) => Promise<RichTextAiApplyResult | {
|
|
324
|
+
document: JSONContent;
|
|
325
|
+
bytes: Uint8Array;
|
|
326
|
+
}>;
|
|
327
|
+
discardStream: (input: {
|
|
328
|
+
streamId: string;
|
|
329
|
+
reason?: string;
|
|
330
|
+
}) => void;
|
|
331
|
+
cancelContext: (id: string) => void;
|
|
332
|
+
onEvent: (handler: (event: RichTextAiBridgeEvent) => void) => () => boolean;
|
|
333
|
+
dispose: () => void;
|
|
334
|
+
};
|
|
335
|
+
export type RichTextAiBridge = ReturnType<typeof createRichTextAiBridge>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RichTextAiBridge } from './bridge';
|
|
2
|
+
export declare function consumeRichTextAiStream(bridge: RichTextAiBridge, source: AsyncIterable<string | Uint8Array>, options: {
|
|
3
|
+
streamId: string;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}): Promise<import('./bridge').RichTextAiApplyResult | {
|
|
6
|
+
document: import('@tiptap/core').JSONContent;
|
|
7
|
+
bytes: Uint8Array;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EditorState, Transaction } from '@tiptap/pm/state';
|
|
2
|
+
import { RichTextPatch } from '../ai-protocol/patch';
|
|
3
|
+
export type RichTextResolvedTarget = {
|
|
4
|
+
ref: string;
|
|
5
|
+
kind: 'cursor' | 'textRange' | 'node' | 'blockSet' | 'tableCells' | 'document';
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
positions?: number[];
|
|
9
|
+
nodeId?: string | null;
|
|
10
|
+
parentRef?: string;
|
|
11
|
+
tableRow?: number;
|
|
12
|
+
tableColumn?: number;
|
|
13
|
+
isHeader?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare class RichTextAiExecutionError extends Error {
|
|
16
|
+
readonly code: 'TARGET_NOT_FOUND' | 'OUT_OF_SCOPE' | 'INVALID_DOCUMENT' | 'UNSUPPORTED_CAPABILITY';
|
|
17
|
+
constructor(code: 'TARGET_NOT_FOUND' | 'OUT_OF_SCOPE' | 'INVALID_DOCUMENT' | 'UNSUPPORTED_CAPABILITY', message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare function buildRichTextPatchTransaction(state: EditorState, patch: RichTextPatch, targets: ReadonlyMap<string, RichTextResolvedTarget>): Transaction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createRichTextAiBridge, RichTextAiBridgeError } from './bridge';
|
|
2
|
+
export { createRichTextToolHandlers } from './tools';
|
|
3
|
+
export type { RichTextToolHost, RichTextToolResult, RichTextToolHandlers } from './tools';
|
|
4
|
+
export type { RichTextExternalReference } from '../ai-protocol/references';
|
|
5
|
+
export { consumeRichTextAiStream } from './consume-stream';
|
|
6
|
+
export { buildRichTextPatchTransaction, RichTextAiExecutionError } from './executor';
|
|
7
|
+
export type { RichTextResolvedTarget } from './executor';
|
|
8
|
+
export type { RichTextAiBridge, RichTextAiBridgeEvent, RichTextAiBridgeOptions, RichTextAiEditorAdapter, RichTextAiEditorInstance, RichTextAiPolicy, RichTextAiWritePolicy, RichTextAiSelectionSnapshot, RichTextAiTarget, RichTextAiTargetClearReason, RichTextAiApplyResult, } from './bridge';
|