@opencxh/domain 1.219.0 → 1.221.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.
@@ -0,0 +1,6 @@
1
+ import { DocumentOperationDescriptor } from './documents';
2
+ export declare const DOCUMENT_OPERATIONS: DocumentOperationDescriptor[];
3
+ /** The descriptors valid on one kind. Used by an adapter to declare, and by the guard to refuse. */
4
+ export declare function operationsForKind(kind: string): DocumentOperationDescriptor[];
5
+ /** One descriptor by name, or `undefined` for an operation nobody declares. */
6
+ export declare function operationDescriptor(op: string): DocumentOperationDescriptor | undefined;
@@ -0,0 +1,142 @@
1
+ import { AiToolParameterSchema } from './ai-tools';
2
+ /**
3
+ * Open editors, readable and drivable across app boundaries.
4
+ *
5
+ * An app that mounts an editor (Univer, pdf.js, a block editor) holds a live document model no
6
+ * other layer can reach. The assistant beside it could neither read it nor change it, so every
7
+ * "what does this say" and "fix that cell" ended at the app boundary.
8
+ *
9
+ * Three keys, all through `sdk.services.execute`, mirroring `resources.*`:
10
+ *
11
+ * | Key | Params | Answer |
12
+ * |---|---|---|
13
+ * | `documents.describe` | {@link DocumentTargetParams} | {@link DocumentCapability} \| `null` |
14
+ * | `documents.inspect` | {@link DocumentInspectParams} | {@link DocumentInspection} \| `null` |
15
+ * | `documents.apply` | {@link DocumentApplyParams} | {@link DocumentApplyResult} \| `null` |
16
+ *
17
+ * A service-bus contract rather than a provider role, for the same reason as `resources.*`: the
18
+ * document only exists in the browser of the user who has it open. There is nothing on the server
19
+ * to ask.
20
+ *
21
+ * **What a server-side AI tool can and cannot do with this.** The tool loop runs on the server and
22
+ * the transport is one-way (`Bridge.sse.push` → the app's SSE handler; handler return values are
23
+ * discarded in `packages/app-sdk/src/modules/api.ts`). So a tool can *deliver* operations and must
24
+ * say so honestly; it cannot read an answer back. Reading therefore travels the other way, as
25
+ * `context.collect` slices that ride the next turn — which doubles as the feedback channel for an
26
+ * operation delivered a turn earlier. {@link DocumentApplyResult} is already shaped as the answer
27
+ * a round trip would return, so adding one later is transport work and not a contract change.
28
+ */
29
+ /** The service-bus keys, as constants so a typo does not silently yield an empty list. */
30
+ export declare const DOCUMENT_DESCRIBE_SERVICE = "documents.describe";
31
+ export declare const DOCUMENT_INSPECT_SERVICE = "documents.inspect";
32
+ export declare const DOCUMENT_APPLY_SERVICE = "documents.apply";
33
+ /**
34
+ * Which document, as `<kind>:<ref>` — `file:<fileId>` for a stored file.
35
+ *
36
+ * Deliberately the same shape as a scopeKey and not a second identifier: it is the key the
37
+ * assistant already groups its conversations on and the key `provider/scope/authorize` gates, so
38
+ * "the document the user is looking at" and "the scope this thread belongs to" stay one thing.
39
+ */
40
+ export type DocumentKey = string;
41
+ /** Params for `documents.describe` and the shared prefix of the other two. */
42
+ export interface DocumentTargetParams {
43
+ docKey: DocumentKey;
44
+ }
45
+ /**
46
+ * One operation an editor accepts, as the editor itself declares it.
47
+ *
48
+ * Declared rather than derived: the same list feeds the AI tool's parameter schema and the
49
+ * adapter's own validation, so the model can never be offered an operation the editor does not
50
+ * implement. Adding a capability is one descriptor plus one handler — no new tool, no prompt
51
+ * change, no server change.
52
+ */
53
+ export interface DocumentOperationDescriptor {
54
+ /** `<kind>.<verb>`, and the prefix *is* the kind: that makes the guard a prefix test. */
55
+ op: string;
56
+ /** The document kinds this operation is valid on. */
57
+ kinds: string[];
58
+ /** One line, model-facing. This is what the assistant reads to choose. */
59
+ summary: string;
60
+ parameters: AiToolParameterSchema;
61
+ /**
62
+ * Can the user undo it with ctrl-Z?
63
+ *
64
+ * Not cosmetic: a Univer facade call goes through the command service and lands in the undo
65
+ * stack, while a snapshot rewrite (slides has no facade at all) does not. The tool result says
66
+ * which, because "I changed it, undo if you disagree" is a promise that has to hold.
67
+ */
68
+ undoable: boolean;
69
+ /**
70
+ * Does the user see the change before saving?
71
+ *
72
+ * `false` means the operation is written on save but not drawn yet — pdf.js draws its editor
73
+ * layer from `AnnotationEditor` instances, so an annotation injected as a plain object into the
74
+ * annotation storage is real to `saveDocument()` and invisible on screen. An invisible change
75
+ * needs to be announced, not assumed.
76
+ */
77
+ visible: boolean;
78
+ }
79
+ /** Answer to `documents.describe`: what is open, and what may be done to it. */
80
+ export interface DocumentCapability {
81
+ docKey: DocumentKey;
82
+ /** `pdf` · `sheet` · `word` · `slides`, or whatever a future editor calls itself. */
83
+ kind: string;
84
+ title: string;
85
+ /** Someone else holds the lock, or a write-back would drop content, or it is read-only. */
86
+ readOnly: boolean;
87
+ /** What a write-back would lose, from the editor's own `unsupportedFeatures`. */
88
+ blocked: string[];
89
+ /** The subset of {@link DOCUMENT_OPERATIONS} this mounted editor actually implements. */
90
+ operations: DocumentOperationDescriptor[];
91
+ }
92
+ /** One operation to apply. The extra keys are the params its descriptor declares. */
93
+ export interface DocumentOperation {
94
+ op: string;
95
+ [key: string]: unknown;
96
+ }
97
+ export interface DocumentApplyParams extends DocumentTargetParams {
98
+ operations: DocumentOperation[];
99
+ }
100
+ /**
101
+ * What applying did. Partial success is the normal case, not an edge: operations arrive as a batch
102
+ * from a model, and one bad range should not discard the other four.
103
+ */
104
+ export interface DocumentApplyResult {
105
+ docKey: DocumentKey;
106
+ applied: number;
107
+ failed: {
108
+ op: string;
109
+ reason: string;
110
+ }[];
111
+ /** Is there unsaved work now? The user still owns the save. */
112
+ dirty: boolean;
113
+ /** How many applied operations are not drawn yet. See {@link DocumentOperationDescriptor.visible}. */
114
+ pending: number;
115
+ }
116
+ /**
117
+ * What to read. Absent `slices` = the cheap overview only.
118
+ *
119
+ * Deliberately not the typed per-kind query tree Univer's inspection API uses: the consumer here
120
+ * is a prompt with a character budget, and the useful question is always "the overview, plus this
121
+ * much content". Names are per kind and documented by the adapter's own descriptor.
122
+ */
123
+ export interface DocumentInspectParams extends DocumentTargetParams {
124
+ slices?: string[];
125
+ /** Character ceiling per slice. The adapter truncates predictably rather than mid-row. */
126
+ budget?: number;
127
+ }
128
+ /** Answer to `documents.inspect`: read-only, kind-shaped, budgeted. */
129
+ export interface DocumentInspection {
130
+ docKey: DocumentKey;
131
+ kind: string;
132
+ /** Per-slice content, already truncated. `truncated` names the slices that were cut. */
133
+ slices: Record<string, unknown>;
134
+ truncated?: string[];
135
+ }
136
+ /**
137
+ * The kind out of a {@link DocumentKey} or an operation name.
138
+ *
139
+ * One helper for both because the operation prefix *is* the kind — `pdf.goToPage` on a `sheet`
140
+ * is a routing mistake, and this is what catches it.
141
+ */
142
+ export declare function documentKindOf(value: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencxh/domain",
3
- "version": "1.219.0",
3
+ "version": "1.221.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",