@norio-office/rich-text 0.8.0 → 0.8.3
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/LICENSE +5 -19
- package/README.md +102 -2310
- package/dist/ai/index.js +58 -57
- package/dist/collaboration-presence.d.ts +11 -0
- package/dist/components/BlockColorPanel.vue.d.ts +2 -2
- package/dist/components/CollaborationPresence.vue.d.ts +6 -0
- package/dist/components/RichTextEditor.vue.d.ts +10 -2
- package/dist/components/TableThemePanel.vue.d.ts +4 -4
- package/dist/composables/useDocumentName.d.ts +15 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7278 -7011
- package/dist/index.umd.cjs +104 -54
- package/dist/style.css +1 -1
- package/dist/types.d.ts +12 -0
- package/docs/file-header.md +50 -0
- package/docs/usage.md +5 -0
- package/examples/ai/browser/App.vue +106 -0
- package/examples/ai/browser/README.md +30 -0
- package/examples/ai/browser/ai-proxy.d.mts +3 -0
- package/examples/ai/browser/ai-proxy.mjs +89 -0
- package/examples/ai/browser/vite.config.ts +3 -2
- package/package.json +5 -4
- package/skills/README.md +23 -0
- package/skills/assets/editor-screenshot.png +0 -0
- package/skills/norio-rich-text/SKILL.md +36 -0
- package/skills/norio-rich-text/examples/basic-document.json +7 -0
- package/skills/norio-rich-text/examples/custom-blocks-document.json +14 -0
- package/skills/norio-rich-text/examples/embedded-file-document.json +6 -0
- package/skills/norio-rich-text/examples/local-edit.json +10 -0
- package/skills/norio-rich-text/examples/media-reference-document.json +8 -0
- package/skills/norio-rich-text/examples/resource-map.json +7 -0
- package/skills/norio-rich-text/examples/sample-attachment.txt +1 -0
- package/skills/norio-rich-text/examples/streamed-document.ndjson +9 -0
- package/skills/norio-rich-text/examples/streamed-selection-edit.ndjson +3 -0
- package/skills/norio-rich-text/examples/styled-document.json +10 -0
- package/skills/norio-rich-text/examples/table-cell-edit.json +10 -0
- package/skills/norio-rich-text/references/document-format.md +17 -0
- package/skills/norio-rich-text/references/integration.md +46 -0
- package/skills/norio-rich-text/references/nordox-format.md +7 -0
- package/skills/norio-rich-text/references/operations.md +13 -0
- package/skills/norio-rich-text/references/streaming.md +15 -0
- package/skills/norio-rich-text/runtime-manifest.json +39 -0
- package/skills/norio-rich-text/schemas/document.schema.json +1580 -0
- package/skills/norio-rich-text/schemas/nordox-manifest.schema.json +105 -0
- package/skills/norio-rich-text/schemas/patch.schema.json +3164 -0
- package/skills/norio-rich-text/schemas/stream-event.schema.json +3409 -0
- package/skills/norio-rich-text/schemas/tool-inputs.schema.json +6028 -0
- package/skills/norio-rich-text/scripts/check-package.mjs +57 -0
- package/skills/norio-rich-text/scripts/generate-schemas.mjs +35 -0
- package/skills/norio-rich-text/scripts/rich-text.mjs +152 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Integration
|
|
2
|
+
|
|
3
|
+
Install `@norio-office/rich-text` and its documented Vue/Tiptap peer dependencies. Pure protocol and Nordox entries work in Node 20+ and browsers; the editor component and Bridge use a browser.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { validateRichTextDocument, getRichTextToolDefinitions } from '@norio-office/rich-text/ai-protocol'
|
|
7
|
+
import { packNordox, unpackNordox } from '@norio-office/rich-text/nordox'
|
|
8
|
+
import { createRichTextAiBridge, createRichTextToolHandlers, consumeRichTextAiStream } from '@norio-office/rich-text/ai'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Bind `createRichTextAiBridge(editorInstance, { documentId, policy, resourceResolver, authorizeExternalReference })` to the actual mounted editor. `createRichTextToolHandlers(bridge, { createDocument, resourceResolver, authorizeExternalReference })` creates handlers for the names in `getRichTextToolDefinitions()`. The Bridge authorizer is a synchronous boolean lookup against host-approved image/video/file IDs or URLs, links, mention IDs and existing comment-thread IDs; the create-document handler also accepts an asynchronous lookup. Missing or denied authorization rejects newly AI-introduced references before preview or commit. It does not reject existing document references, create threads, or upload files. The host must also authorize document/session access, provide model transport, call the correct handler, persist returned Nordox bytes, and manage chat history. The package does not create application tabs, database rows, API keys, or model requests.
|
|
12
|
+
|
|
13
|
+
For an explicit user-selected AI editing scope, set `<RichTextEditor :show-ai-target-button="true" />`. Subscribe to `bridge.onEvent`; `ai-target-change` carries the selected target or `null` when the editor body, marker close button, host, commit, or lifecycle clears it. On send, call `bridge.getAiTarget()` and pass its `targetId` to `bridge.createEditContext({ requestId, instruction, targetId })`; then use only returned `targetRefs`. A repeated toolbar click keeps the same target when selection is unchanged. The host range-card close button calls `bridge.clearAiTarget({ targetId, reason: 'host-close' })` and cancels its own model request. Clearing invalidates uncommitted contexts and streams locally; it does not cancel remote transport by itself. The legacy context-without-`targetId` path remains for older hosts.
|
|
14
|
+
|
|
15
|
+
Tool results use `{ ok: true, data }` or `{ ok: false, error: { code, message, retryable, requiresContextRefresh } }`. When `requiresContextRefresh` is true (`TARGET_CHANGED`, `TARGET_NOT_FOUND`, `CONTEXT_EXPIRED`, or `DOCUMENT_NOT_FOUND`), obtain a fresh context/selection and read the target again before retrying; do not fall back to overwriting the whole document. An exception from the host `createDocument` callback, or a callback that returns no nonempty `documentId`, becomes `DOCUMENT_SAVE_FAILED` with `retryable: true` and `requiresContextRefresh: false`; the original exception text is not sent to the model. Keep detailed storage diagnostics in the host's own logs, not in tool responses. Unknown exceptions are likewise returned as a generic `TOOL_EXECUTION_FAILED` rather than exposing paths, credentials or document content.
|
|
16
|
+
|
|
17
|
+
For a model that only returns complete JSON, the host can validate it against the same public input schema and then call the same handler. For example, with a host-installed JSON Schema 2020-12 validator such as Ajv:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import Ajv2020 from 'ajv/dist/2020.js'
|
|
21
|
+
import { getRichTextToolDefinitions } from '@norio-office/rich-text/ai-protocol'
|
|
22
|
+
import { createRichTextToolHandlers } from '@norio-office/rich-text/ai'
|
|
23
|
+
|
|
24
|
+
const definition = getRichTextToolDefinitions().find(tool => tool.name === 'richtext_apply_patch')!
|
|
25
|
+
const validate = new Ajv2020({ strict: false }).compile(definition.inputSchema)
|
|
26
|
+
function applyCompleteModelJson(raw: string, handlers: ReturnType<typeof createRichTextToolHandlers>) {
|
|
27
|
+
const input: unknown = JSON.parse(raw) // Reject incomplete JSON; do not apply it.
|
|
28
|
+
if (!validate(input)) throw new Error('Invalid rich-text patch')
|
|
29
|
+
return handlers.richtext_apply_patch(input)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Invoke this only after the model has finished its complete response. For incremental display, use the NDJSON stream path below instead; never animate a completed JSON result and describe it as streaming.
|
|
34
|
+
|
|
35
|
+
For a stream, call `bridge.beginStream(...)`, then pass the source `AsyncIterable<string | Uint8Array>` to `consumeRichTextAiStream(bridge, source, { streamId, signal })`. That function forwards complete decoded events while chunks arrive and commits only after transport ends normally. On failure it discards preview. Do not call `modelValue = newDocument` to apply a local edit; Bridge dispatches its own scoped transaction. In a Vue host, `update:modelValue` remains the one persistence change path; use the AI `applied` event for provenance, not a second save.
|
|
36
|
+
|
|
37
|
+
Offline CLI examples (run from a copied Skill directory with the package installed):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
node scripts/rich-text.mjs capabilities
|
|
41
|
+
node scripts/rich-text.mjs validate-document --input examples/basic-document.json
|
|
42
|
+
node scripts/rich-text.mjs create --input examples/basic-document.json --output result.nordox
|
|
43
|
+
node scripts/rich-text.mjs create --stream --input - --output result.nordox < examples/streamed-document.ndjson
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The CLI does not bind a live editor. NorioWork imports `SKILL.md` text but does not automatically register or run `scripts/`; its application team must bind tools and resources separately.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Nordox Container
|
|
2
|
+
|
|
3
|
+
`.nordox` is a ZIP with `manifest.json`, `document.json`, and optional `assets/images/`, `assets/videos/`, and `assets/files/` entries. `manifest.json` records format version 1, schema version, title, packaging policy, and resources. This file is separate from Skill `runtime-manifest.json`.
|
|
4
|
+
|
|
5
|
+
The model generates native JSON or stream events, never ZIP bytes. `packNordox` validates and creates the ZIP; `unpackNordox` verifies paths, sizes, format versions, document structure, and resource references. Embedded resources are stored as original bytes without transcoding. Different resource IDs with identical bytes, kind, and MIME type may share one ZIP asset path; each ID remains separately listed in the manifest and document. Their `nordox:asset/<id>` reference is converted to a temporary display URL only by the browser adapter; the temporary URL is never persisted.
|
|
6
|
+
|
|
7
|
+
`assetPackaging` has `images`, `videos`, and `files` settings, each `embed` or `reference`. A missing setting preserves an already embedded resource; a new external resource defaults to `reference`. Embedding needs a host byte resolver. A reference needs a persistent address, not `blob:`, `data:`, `file:`, or a credential-bearing URL. Failed preparation must leave the existing document and file untouched.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Local Operations
|
|
2
|
+
|
|
3
|
+
All local edits require the host-bound `documentId`, `contextId`, `requestId`, `baseRevision`, and an authorized `targetRef`. These are ProseMirror/Yjs targets, not character offsets.
|
|
4
|
+
|
|
5
|
+
Supported operation names: `insertContent`, `replaceText`, `replaceFragment`, `setMarks`, `unsetMarks`, `setNodeAttributes`, `unsetNodeAttributes`, `deleteContent`, `moveBlocks`, `transformBlocks`, and `tableOperation`. The structural schema is `schemas/patch.schema.json`; runtime target and permission checks happen only in the editor Bridge.
|
|
6
|
+
|
|
7
|
+
Example, replace a selected phrase:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{"protocolVersion":1,"documentId":"HOST_ID","requestId":"HOST_REQUEST","contextId":"HOST_CONTEXT","baseRevision":0,"operations":[{"type":"replaceText","targetRef":"HOST_TARGET","text":"Revised phrase"}]}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For color, use `setMarks` with the registered `textStyle` Mark attributes. For a highlighted block, use `setNodeAttributes` on a `highlightBlock`; for a table cell use `tableOperation` or a cell attribute operation. A changed/deleted target must be reselected. Never substitute a whole-document write after a local conflict.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Streaming Events
|
|
2
|
+
|
|
3
|
+
The host binds `streamId`, target, mode, and permissions. An event has `protocolVersion:1`, `streamId`, increasing `seq`, `type`, and `payload`. Transport is UTF-8 NDJSON; each line is one complete JSON event. Do not output prose or Markdown fences in the event stream.
|
|
4
|
+
|
|
5
|
+
For a paragraph still being generated, emit several deltas before closing it:
|
|
6
|
+
|
|
7
|
+
```ndjson
|
|
8
|
+
{"protocolVersion":1,"streamId":"HOST_STREAM","seq":1,"type":"node.open","payload":{"nodeRef":"p1","nodeType":"paragraph"}}
|
|
9
|
+
{"protocolVersion":1,"streamId":"HOST_STREAM","seq":2,"type":"text.delta","payload":{"nodeRef":"p1","text":"The first part "}}
|
|
10
|
+
{"protocolVersion":1,"streamId":"HOST_STREAM","seq":3,"type":"text.delta","payload":{"nodeRef":"p1","text":"appears immediately."}}
|
|
11
|
+
{"protocolVersion":1,"streamId":"HOST_STREAM","seq":4,"type":"node.close","payload":{"nodeRef":"p1"}}
|
|
12
|
+
{"protocolVersion":1,"streamId":"HOST_STREAM","seq":5,"type":"stream.end","payload":{}}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`node.attrs` may update attributes of the current open node. `operation` queues one structured patch operation in `operations` mode. In `replaceText` mode, send `text.delta` to the host replacement slot instead of wrapping a paragraph. Close nodes in reverse opening order. `stream.end` is necessary but not sufficient for success: only the host can confirm normal transport completion, validate the final result, and call commit. Cancellation/errors discard the local preview without changing official content.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "norio-rich-text",
|
|
3
|
+
"skillVersion": "1.0.0",
|
|
4
|
+
"protocolVersion": 1,
|
|
5
|
+
"schemaVersion": "1",
|
|
6
|
+
"streamProtocolVersion": 1,
|
|
7
|
+
"minimumNodeVersion": "20.0.0",
|
|
8
|
+
"package": "@norio-office/rich-text",
|
|
9
|
+
"entrypoints": ["@norio-office/rich-text/ai-protocol", "@norio-office/rich-text/ai", "@norio-office/rich-text/nordox"],
|
|
10
|
+
"tools": ["richtext_get_capabilities", "richtext_create_document", "richtext_read_document", "richtext_get_selection", "richtext_read_target", "richtext_apply_patch"],
|
|
11
|
+
"files": [
|
|
12
|
+
"SKILL.md",
|
|
13
|
+
"runtime-manifest.json",
|
|
14
|
+
"references/document-format.md",
|
|
15
|
+
"references/nordox-format.md",
|
|
16
|
+
"references/operations.md",
|
|
17
|
+
"references/streaming.md",
|
|
18
|
+
"references/integration.md",
|
|
19
|
+
"schemas/document.schema.json",
|
|
20
|
+
"schemas/nordox-manifest.schema.json",
|
|
21
|
+
"schemas/patch.schema.json",
|
|
22
|
+
"schemas/stream-event.schema.json",
|
|
23
|
+
"schemas/tool-inputs.schema.json",
|
|
24
|
+
"examples/basic-document.json",
|
|
25
|
+
"examples/styled-document.json",
|
|
26
|
+
"examples/custom-blocks-document.json",
|
|
27
|
+
"examples/media-reference-document.json",
|
|
28
|
+
"examples/embedded-file-document.json",
|
|
29
|
+
"examples/local-edit.json",
|
|
30
|
+
"examples/table-cell-edit.json",
|
|
31
|
+
"examples/streamed-document.ndjson",
|
|
32
|
+
"examples/streamed-selection-edit.ndjson",
|
|
33
|
+
"examples/resource-map.json",
|
|
34
|
+
"examples/sample-attachment.txt",
|
|
35
|
+
"scripts/rich-text.mjs",
|
|
36
|
+
"scripts/generate-schemas.mjs",
|
|
37
|
+
"scripts/check-package.mjs"
|
|
38
|
+
]
|
|
39
|
+
}
|