@norio-office/rich-text 0.7.1 → 0.8.2

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 (92) hide show
  1. package/LICENSE +5 -19
  2. package/README.md +82 -2260
  3. package/dist/ai/bridge.d.ts +335 -0
  4. package/dist/ai/consume-stream.d.ts +8 -0
  5. package/dist/ai/executor.d.ts +19 -0
  6. package/dist/ai/index.d.ts +8 -0
  7. package/dist/ai/index.js +4106 -0
  8. package/dist/ai/tools.d.ts +158 -0
  9. package/dist/ai-protocol/index.d.ts +12 -0
  10. package/dist/ai-protocol/index.js +2372 -0
  11. package/dist/ai-protocol/json-schema.d.ts +5 -0
  12. package/dist/ai-protocol/patch.d.ts +77 -0
  13. package/dist/ai-protocol/references.d.ts +11 -0
  14. package/dist/ai-protocol/stream.d.ts +94 -0
  15. package/dist/ai-protocol/tools.d.ts +8 -0
  16. package/dist/ai-protocol/validation.d.ts +20 -0
  17. package/dist/components/RichTextEditor.vue.d.ts +11 -4
  18. package/dist/document/ai-identity.d.ts +4 -0
  19. package/dist/document/nodes/columns-block.d.ts +2 -0
  20. package/dist/document/nodes/countdown-block.d.ts +2 -0
  21. package/dist/document/nodes/formula-block.d.ts +2 -0
  22. package/dist/document/nodes/highlight-block.d.ts +2 -0
  23. package/dist/document/nodes/image-block.d.ts +8 -0
  24. package/dist/document/nodes/link-block.d.ts +2 -0
  25. package/dist/document/nodes/local-file-block.d.ts +2 -0
  26. package/dist/document/nodes/mention.d.ts +2 -0
  27. package/dist/document/nodes/office-code-block.d.ts +1 -0
  28. package/dist/document/nodes/table-cells.d.ts +2 -0
  29. package/dist/document/nodes/themed-table.d.ts +1 -0
  30. package/dist/document/nodes/video-block.d.ts +8 -0
  31. package/dist/document/schema.d.ts +17 -0
  32. package/dist/extensions/ai-identity.d.ts +1 -0
  33. package/dist/extensions/columns-block.d.ts +1 -2
  34. package/dist/extensions/countdown-block.d.ts +1 -2
  35. package/dist/extensions/formula-block.d.ts +1 -2
  36. package/dist/extensions/highlight-block.d.ts +1 -2
  37. package/dist/extensions/image-block.d.ts +4 -8
  38. package/dist/extensions/link-block.d.ts +1 -2
  39. package/dist/extensions/local-file-block.d.ts +1 -2
  40. package/dist/extensions/mention.d.ts +1 -2
  41. package/dist/extensions/video-block.d.ts +4 -8
  42. package/dist/{html2canvas-4hiP1s1t.js → html2canvas-BnDzIoab.js} +112 -126
  43. package/dist/index.js +8343 -7407
  44. package/dist/index.umd.cjs +2196 -1995
  45. package/dist/nordox/index.d.ts +95 -0
  46. package/dist/nordox/index.js +2094 -0
  47. package/dist/{chunk-C_CI6nMA.js → rolldown-runtime-VHNaYcLd.js} +3 -3
  48. package/dist/style.css +1 -1
  49. package/dist/types.d.ts +9 -1
  50. package/docs/ai/README.md +108 -0
  51. package/docs/ai/acceptance-report.md +88 -0
  52. package/docs/ai/capability-matrix.md +43 -0
  53. package/docs/ai/compatibility.md +9 -0
  54. package/docs/icons.md +21 -0
  55. package/examples/ai/browser/App.vue +257 -0
  56. package/examples/ai/browser/README.md +30 -0
  57. package/examples/ai/browser/ai-proxy.d.mts +3 -0
  58. package/examples/ai/browser/ai-proxy.mjs +89 -0
  59. package/examples/ai/browser/index.html +12 -0
  60. package/examples/ai/browser/main.ts +5 -0
  61. package/examples/ai/browser/tsconfig.json +7 -0
  62. package/examples/ai/browser/vite.config.ts +15 -0
  63. package/examples/ai/node.mjs +28 -0
  64. package/package.json +18 -3
  65. package/skills/README.md +23 -0
  66. package/skills/assets/editor-screenshot.png +0 -0
  67. package/skills/norio-rich-text/SKILL.md +36 -0
  68. package/skills/norio-rich-text/examples/basic-document.json +7 -0
  69. package/skills/norio-rich-text/examples/custom-blocks-document.json +14 -0
  70. package/skills/norio-rich-text/examples/embedded-file-document.json +6 -0
  71. package/skills/norio-rich-text/examples/local-edit.json +10 -0
  72. package/skills/norio-rich-text/examples/media-reference-document.json +8 -0
  73. package/skills/norio-rich-text/examples/resource-map.json +7 -0
  74. package/skills/norio-rich-text/examples/sample-attachment.txt +1 -0
  75. package/skills/norio-rich-text/examples/streamed-document.ndjson +9 -0
  76. package/skills/norio-rich-text/examples/streamed-selection-edit.ndjson +3 -0
  77. package/skills/norio-rich-text/examples/styled-document.json +10 -0
  78. package/skills/norio-rich-text/examples/table-cell-edit.json +10 -0
  79. package/skills/norio-rich-text/references/document-format.md +17 -0
  80. package/skills/norio-rich-text/references/integration.md +46 -0
  81. package/skills/norio-rich-text/references/nordox-format.md +7 -0
  82. package/skills/norio-rich-text/references/operations.md +13 -0
  83. package/skills/norio-rich-text/references/streaming.md +15 -0
  84. package/skills/norio-rich-text/runtime-manifest.json +39 -0
  85. package/skills/norio-rich-text/schemas/document.schema.json +1580 -0
  86. package/skills/norio-rich-text/schemas/nordox-manifest.schema.json +105 -0
  87. package/skills/norio-rich-text/schemas/patch.schema.json +3164 -0
  88. package/skills/norio-rich-text/schemas/stream-event.schema.json +3409 -0
  89. package/skills/norio-rich-text/schemas/tool-inputs.schema.json +6028 -0
  90. package/skills/norio-rich-text/scripts/check-package.mjs +57 -0
  91. package/skills/norio-rich-text/scripts/generate-schemas.mjs +35 -0
  92. package/skills/norio-rich-text/scripts/rich-text.mjs +152 -0
@@ -0,0 +1,57 @@
1
+ import { readFile, stat } from 'node:fs/promises'
2
+ import { dirname, join, resolve } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ import {
6
+ createRichTextStreamBuilder, createRichTextStreamDecoder,
7
+ getRichTextToolDefinitions, validateRichTextDocument, validateRichTextPatch,
8
+ } from '@norio-office/rich-text/ai-protocol'
9
+ import { packNordox, unpackNordox } from '@norio-office/rich-text/nordox'
10
+
11
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
12
+ const manifest = JSON.parse(await readFile(join(root, 'runtime-manifest.json'), 'utf8'))
13
+ const listed = new Set(manifest.files)
14
+ for (const relative of listed) {
15
+ const path = resolve(root, relative)
16
+ if (!path.startsWith(`${root}\\`) && !path.startsWith(`${root}/`)) throw new Error(`Unsafe listed path: ${relative}`)
17
+ if (!(await stat(path)).isFile()) throw new Error(`Not a file: ${relative}`)
18
+ }
19
+ for (const name of getRichTextToolDefinitions().map(tool => tool.name)) {
20
+ if (!manifest.tools.includes(name)) throw new Error(`Missing tool in manifest: ${name}`)
21
+ }
22
+ for (const name of ['basic-document', 'styled-document', 'custom-blocks-document', 'media-reference-document', 'embedded-file-document']) {
23
+ const value = JSON.parse(await readFile(join(root, 'examples', `${name}.json`), 'utf8'))
24
+ const result = validateRichTextDocument(value)
25
+ if (!result.valid) throw new Error(`${name}: ${JSON.stringify(result.errors)}`)
26
+ }
27
+ for (const name of ['local-edit', 'table-cell-edit']) {
28
+ const value = JSON.parse(await readFile(join(root, 'examples', `${name}.json`), 'utf8'))
29
+ const result = validateRichTextPatch(value)
30
+ if (!result.valid) throw new Error(`${name}: ${JSON.stringify(result.errors)}`)
31
+ }
32
+ for (const [name, mode] of [['streamed-document', 'createDocument'], ['streamed-selection-edit', 'replaceText']]) {
33
+ const decoder = createRichTextStreamDecoder()
34
+ const source = await readFile(join(root, 'examples', `${name}.ndjson`))
35
+ let builder
36
+ for (const event of decoder.push(source)) {
37
+ builder ??= createRichTextStreamBuilder({ streamId: event.streamId, mode })
38
+ builder.append(event)
39
+ }
40
+ decoder.finish()
41
+ builder?.result()
42
+ }
43
+ const example = JSON.parse(await readFile(join(root, 'examples/basic-document.json'), 'utf8'))
44
+ const archive = await packNordox(example)
45
+ await unpackNordox(archive)
46
+ const mediaExample = JSON.parse(await readFile(join(root, 'examples/media-reference-document.json'), 'utf8'))
47
+ const mediaArchive = await unpackNordox(await packNordox(mediaExample, {
48
+ assetPackaging: { images: 'reference', videos: 'reference', files: 'reference' },
49
+ }))
50
+ if (mediaArchive.manifest.resources.length !== 3 || mediaArchive.manifest.resources.some(resource => resource.storage !== 'external')) {
51
+ throw new Error('Media reference example did not produce three external resources.')
52
+ }
53
+ const skill = await readFile(join(root, 'SKILL.md'), 'utf8')
54
+ for (const link of skill.matchAll(/\]\((references\/[^)]+)\)/g)) {
55
+ if (!listed.has(link[1])) throw new Error(`Unlisted Skill reference: ${link[1]}`)
56
+ }
57
+ process.stdout.write(`Skill package verified: ${listed.size} files\n`)
@@ -0,0 +1,35 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises'
2
+ import { dirname, join } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ import {
6
+ getRichTextDocumentJsonSchema,
7
+ getRichTextPatchJsonSchema,
8
+ getRichTextStreamEventJsonSchema,
9
+ getRichTextToolDefinitions,
10
+ } from '@norio-office/rich-text/ai-protocol'
11
+ import { getNordoxManifestJsonSchema } from '@norio-office/rich-text/nordox'
12
+
13
+ const directory = join(dirname(fileURLToPath(import.meta.url)), '..', 'schemas')
14
+ const schemas = {
15
+ 'document.schema.json': getRichTextDocumentJsonSchema(),
16
+ 'nordox-manifest.schema.json': getNordoxManifestJsonSchema(),
17
+ 'patch.schema.json': getRichTextPatchJsonSchema(),
18
+ 'stream-event.schema.json': getRichTextStreamEventJsonSchema(),
19
+ 'tool-inputs.schema.json': {
20
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
21
+ $id: 'https://norio-office.github.io/rich-text/tool-inputs.schema.json',
22
+ $defs: Object.fromEntries(getRichTextToolDefinitions().map(tool => [tool.name, tool.inputSchema])),
23
+ },
24
+ }
25
+
26
+ const write = process.argv.includes('--write')
27
+ if (!write && !process.argv.includes('--check')) throw new Error('Use --write or --check')
28
+ if (write) await mkdir(directory, { recursive: true })
29
+ for (const [name, schema] of Object.entries(schemas)) {
30
+ const path = join(directory, name)
31
+ const content = `${JSON.stringify(schema, null, 2)}\n`
32
+ if (write) await writeFile(path, content)
33
+ else if (await readFile(path, 'utf8') !== content) throw new Error(`${name} is out of sync; run --write`)
34
+ }
35
+ process.stdout.write(`${write ? 'Generated' : 'Checked'} ${Object.keys(schemas).length} schemas\n`)
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+ import { createReadStream } from 'node:fs'
3
+ import { open, readFile } from 'node:fs/promises'
4
+ import { extname } from 'node:path'
5
+ import process from 'node:process'
6
+
7
+ import {
8
+ createRichTextStreamBuilder,
9
+ createRichTextStreamDecoder,
10
+ getRichTextDocumentSchema,
11
+ getRichTextToolDefinitions,
12
+ validateRichTextDocument,
13
+ validateRichTextPatch,
14
+ } from '@norio-office/rich-text/ai-protocol'
15
+ import { packNordox, unpackNordox } from '@norio-office/rich-text/nordox'
16
+
17
+ function argumentsOf(argv) {
18
+ const [command, ...rest] = argv
19
+ const options = {}
20
+ for (let index = 0; index < rest.length; index++) {
21
+ const argument = rest[index]
22
+ if (!argument.startsWith('--')) throw new Error(`Unexpected argument: ${argument}`)
23
+ const name = argument.slice(2)
24
+ if (name === 'stream') options.stream = true
25
+ else {
26
+ const value = rest[++index]
27
+ if (value === undefined) throw new Error(`Missing value for ${argument}`)
28
+ options[name] = value
29
+ }
30
+ }
31
+ return { command, options }
32
+ }
33
+
34
+ async function inputBytes(path) {
35
+ if (!path) throw new Error('--input is required')
36
+ if (path === '-') {
37
+ const chunks = []
38
+ for await (const chunk of process.stdin) chunks.push(chunk)
39
+ return Buffer.concat(chunks)
40
+ }
41
+ return readFile(path)
42
+ }
43
+
44
+ async function* inputChunks(path) {
45
+ if (!path) throw new Error('--input is required')
46
+ const source = path === '-' ? process.stdin : createReadStream(path)
47
+ for await (const chunk of source) yield chunk
48
+ }
49
+
50
+ async function streamDocument(path, mode = 'createDocument') {
51
+ const decoder = createRichTextStreamDecoder()
52
+ let builder
53
+ for await (const chunk of inputChunks(path)) {
54
+ for (const event of decoder.push(chunk)) {
55
+ builder ??= createRichTextStreamBuilder({ streamId: event.streamId, mode })
56
+ builder.append(event)
57
+ }
58
+ }
59
+ decoder.finish()
60
+ if (!builder) throw new Error('Stream contains no events')
61
+ return builder.result()
62
+ }
63
+
64
+ function assetPackaging(options) {
65
+ const packaging = {}
66
+ for (const kind of ['images', 'videos', 'files']) {
67
+ const mode = options[`asset-${kind}`]
68
+ if (mode !== undefined) {
69
+ if (mode !== 'embed' && mode !== 'reference') throw new Error(`--asset-${kind} must be embed or reference`)
70
+ packaging[kind] = mode
71
+ }
72
+ }
73
+ return packaging
74
+ }
75
+
76
+ async function resourceResolver(path) {
77
+ if (!path) return undefined
78
+ const raw = JSON.parse(await readFile(path, 'utf8'))
79
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw new Error('Resource map must be an object')
80
+ return {
81
+ async readBytes(ref) {
82
+ const entry = raw[ref.id]
83
+ if (!entry || typeof entry.path !== 'string') throw new Error(`Resource ${ref.id} is not mapped`)
84
+ return { bytes: await readFile(entry.path), mimeType: entry.mimeType, name: entry.name }
85
+ },
86
+ }
87
+ }
88
+
89
+ async function writeNewFile(path, bytes) {
90
+ if (!path) throw new Error('--output is required')
91
+ const file = await open(path, 'wx')
92
+ try {
93
+ await file.writeFile(bytes)
94
+ } catch (error) {
95
+ await file.close()
96
+ throw error
97
+ }
98
+ await file.close()
99
+ }
100
+
101
+ async function main() {
102
+ const { command, options } = argumentsOf(process.argv.slice(2))
103
+ if (command === 'capabilities') {
104
+ const schema = getRichTextDocumentSchema()
105
+ return { schemaVersion: '1', protocolVersion: 1, streamProtocolVersion: 1,
106
+ nodes: Object.keys(schema.nodes), marks: Object.keys(schema.marks), tools: getRichTextToolDefinitions().map(tool => tool.name) }
107
+ }
108
+ if (command === 'validate-document') {
109
+ const bytes = await inputBytes(options.input)
110
+ if (extname(options.input ?? '').toLowerCase() === '.nordox' || bytes[0] === 0x50 && bytes[1] === 0x4b) {
111
+ const unpacked = await unpackNordox(bytes)
112
+ return { valid: true, format: 'nordox', title: unpacked.manifest.title, resources: unpacked.manifest.resources.length }
113
+ }
114
+ const result = validateRichTextDocument(JSON.parse(bytes.toString('utf8')))
115
+ if (!result.valid) throw new Error(JSON.stringify(result.errors))
116
+ return { valid: true, format: 'json', schemaVersion: result.schemaVersion }
117
+ }
118
+ if (command === 'validate-patch') {
119
+ const value = JSON.parse((await inputBytes(options.input)).toString('utf8'))
120
+ const result = validateRichTextPatch(value)
121
+ if (!result.valid) throw new Error(JSON.stringify(result.errors))
122
+ return { valid: true, structuralOnly: true, operations: result.patch.operations.length }
123
+ }
124
+ if (command === 'validate-stream') {
125
+ const result = await streamDocument(options.input, options.mode ?? 'createDocument')
126
+ return { valid: true, mode: result.mode, events: result.seq, nodes: result.nodes.length, operations: result.operations.length }
127
+ }
128
+ if (command === 'create') {
129
+ let document
130
+ if (options.stream) {
131
+ const result = await streamDocument(options.input)
132
+ document = { type: 'doc', content: result.nodes }
133
+ } else {
134
+ document = JSON.parse((await inputBytes(options.input)).toString('utf8'))
135
+ }
136
+ const bytes = await packNordox(document, {
137
+ title: options.title ?? 'Untitled',
138
+ assetPackaging: assetPackaging(options),
139
+ resourceResolver: await resourceResolver(options['resource-map']),
140
+ })
141
+ await writeNewFile(options.output, bytes)
142
+ return { created: true, format: 'nordox', output: options.output, byteLength: bytes.byteLength }
143
+ }
144
+ throw new Error('Usage: rich-text.mjs capabilities | validate-document | validate-patch | validate-stream | create [--input path|-] [--output path] [--stream]')
145
+ }
146
+
147
+ main().then(result => {
148
+ process.stdout.write(`${JSON.stringify(result)}\n`)
149
+ }).catch(error => {
150
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`)
151
+ process.exitCode = 1
152
+ })