aicommunicator 0.0.0-stage → 0.2.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/LICENSE +55 -0
- package/README.md +93 -2
- package/bin/aic.js +20427 -0
- package/host-ui/host.js +5151 -0
- package/host-ui/index.html +483 -0
- package/host-ui/lang-en.js +631 -0
- package/package.json +30 -4
- package/plugin-guide.md +997 -0
- package/plugins/plugin-animation/LICENSE +55 -0
- package/plugins/plugin-animation/dist/logic.js +2225 -0
- package/plugins/plugin-animation/docs/manual.md +217 -0
- package/plugins/plugin-animation/manifest.json +31 -0
- package/plugins/plugin-animation/ui/icon.svg +6 -0
- package/plugins/plugin-animation/ui/index.html +2266 -0
- package/plugins/plugin-html-design/LICENSE +55 -0
- package/plugins/plugin-html-design/dist/logic.js +972 -0
- package/plugins/plugin-html-design/docs/manual.md +100 -0
- package/plugins/plugin-html-design/manifest.json +39 -0
- package/plugins/plugin-html-design/samples/exhibition-page.json +570 -0
- package/plugins/plugin-html-design/ui/icon.svg +5 -0
- package/plugins/plugin-html-design/ui/index.html +1241 -0
- package/plugins/plugin-html-slides/LICENSE +55 -0
- package/plugins/plugin-html-slides/dist/logic.js +1323 -0
- package/plugins/plugin-html-slides/docs/manual.md +121 -0
- package/plugins/plugin-html-slides/manifest.json +39 -0
- package/plugins/plugin-html-slides/samples/first-week-lecture.json +1129 -0
- package/plugins/plugin-html-slides/ui/icon.svg +5 -0
- package/plugins/plugin-html-slides/ui/index.html +1349 -0
- package/plugins/plugin-mindmap/LICENSE +55 -0
- package/plugins/plugin-mindmap/dist/logic.js +966 -0
- package/plugins/plugin-mindmap/docs/manual.md +145 -0
- package/plugins/plugin-mindmap/manifest.json +39 -0
- package/plugins/plugin-mindmap/samples/book-club.json +480 -0
- package/plugins/plugin-mindmap/ui/icon.svg +5 -0
- package/plugins/plugin-mindmap/ui/index.html +1774 -0
- package/plugins/plugin-plan/LICENSE +55 -0
- package/plugins/plugin-plan/dist/logic.js +1029 -0
- package/plugins/plugin-plan/docs/manual.md +261 -0
- package/plugins/plugin-plan/manifest.json +51 -0
- package/plugins/plugin-plan/samples/kimchi-day.json +1514 -0
- package/plugins/plugin-plan/samples/meeting-outline.json +653 -0
- package/plugins/plugin-plan/samples/reading-class.json +1577 -0
- package/plugins/plugin-plan/ui/icon.svg +7 -0
- package/plugins/plugin-plan/ui/index.html +1523 -0
- package/plugins/plugin-png/LICENSE +55 -0
- package/plugins/plugin-png/dist/logic.js +1758 -0
- package/plugins/plugin-png/docs/manual.md +344 -0
- package/plugins/plugin-png/manifest.json +35 -0
- package/plugins/plugin-png/ui/icon.svg +5 -0
- package/plugins/plugin-png/ui/index.html +2885 -0
- package/plugins/plugin-process-log/LICENSE +55 -0
- package/plugins/plugin-process-log/dist/logic.js +406 -0
- package/plugins/plugin-process-log/docs/manual.md +131 -0
- package/plugins/plugin-process-log/manifest.json +43 -0
- package/plugins/plugin-process-log/samples/design-decisions.json +241 -0
- package/plugins/plugin-process-log/ui/icon.svg +7 -0
- package/plugins/plugin-process-log/ui/index.html +721 -0
- package/plugins/plugin-story/LICENSE +55 -0
- package/plugins/plugin-story/dist/logic.js +2201 -0
- package/plugins/plugin-story/docs/manual.md +428 -0
- package/plugins/plugin-story/manifest.json +49 -0
- package/plugins/plugin-story/samples/scene-body.json +758 -0
- package/plugins/plugin-story/samples/time-and-groups.json +989 -0
- package/plugins/plugin-story/ui/icon.svg +4 -0
- package/plugins/plugin-story/ui/index.html +2783 -0
- package/plugins/plugin-svg/LICENSE +55 -0
- package/plugins/plugin-svg/dist/logic.js +2150 -0
- package/plugins/plugin-svg/docs/manual.md +314 -0
- package/plugins/plugin-svg/manifest.json +45 -0
- package/plugins/plugin-svg/samples/rocket-icon.json +1305 -0
- package/plugins/plugin-svg/samples/yard-cat.json +7796 -0
- package/plugins/plugin-svg/ui/icon.svg +4 -0
- package/plugins/plugin-svg/ui/index.html +2017 -0
- package/plugins/plugin-tree/LICENSE +55 -0
- package/plugins/plugin-tree/dist/logic.js +505 -0
- package/plugins/plugin-tree/docs/manual.md +140 -0
- package/plugins/plugin-tree/manifest.json +45 -0
- package/plugins/plugin-tree/samples/book-club.json +473 -0
- package/plugins/plugin-tree/samples/sort-memos.json +604 -0
- package/plugins/plugin-tree/ui/icon.svg +7 -0
- package/plugins/plugin-tree/ui/index.html +1305 -0
- package/schema/aic_describe.input.json +11 -0
- package/schema/aic_describe.output.json +67 -0
- package/schema/aic_observe.input.json +14 -0
- package/schema/aic_observe.output.json +47 -0
- package/schema/aic_send.input.json +15 -0
- package/schema/aic_send.output.json +38 -0
- package/schema/aic_update.input.json +19 -0
- package/schema/aic_update.output.json +39 -0
- package/schema/common.json +127 -0
- package/template/plugin/LICENSE +55 -0
- package/template/plugin/README.md +27 -0
- package/template/plugin/docs/manual.md +31 -0
- package/template/plugin/logic.js +337 -0
- package/template/plugin/manifest.json +27 -0
- package/template/plugin/ui/icon.svg +4 -0
- package/template/plugin/ui/index.html +269 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// packages/plugin-sdk/src/index.ts
|
|
4
|
+
var SEPARATOR = " ";
|
|
5
|
+
var ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6
|
+
function sortKey(order, id) {
|
|
7
|
+
return `${order}${SEPARATOR}${id}`;
|
|
8
|
+
}
|
|
9
|
+
function boundAfterOrder(order) {
|
|
10
|
+
return `${order}!`;
|
|
11
|
+
}
|
|
12
|
+
function between(lo, hi) {
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const c of ALPHABET) {
|
|
15
|
+
if ((lo === void 0 || c > lo) && (hi === void 0 || c < hi)) out.push(c);
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function orderBetween(left, right) {
|
|
20
|
+
if (left === void 0 && right === void 0) return "V";
|
|
21
|
+
const L = left ?? "";
|
|
22
|
+
const U = right;
|
|
23
|
+
if (U !== void 0 && !(L < U)) throw new Error(`orderBetween: \uC67C\uCABD ${L} \uC774 \uC624\uB978\uCABD ${U} \uBCF4\uB2E4 \uC55E\uC774\uC5B4\uC57C \uD55C\uB2E4`);
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (U !== void 0 && i < L.length && i < U.length && L[i] === U[i]) i += 1;
|
|
26
|
+
if (U === void 0) i = 0;
|
|
27
|
+
if (i >= L.length && U !== void 0) {
|
|
28
|
+
let prefix = U.slice(0, i);
|
|
29
|
+
for (let k = i; k < U.length; k += 1) {
|
|
30
|
+
const uc2 = U[k];
|
|
31
|
+
const cands2 = between(void 0, uc2);
|
|
32
|
+
if (cands2.length > 0) return prefix + cands2[cands2.length - 1];
|
|
33
|
+
if (prefix !== "" && !prefix.endsWith(SEPARATOR) && uc2 > SEPARATOR) return prefix;
|
|
34
|
+
prefix += uc2;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`orderBetween: ${L} \uACFC ${U} \uC0AC\uC774\uC5D0 \uAC12\uC744 \uB9CC\uB4E4 \uC218 \uC5C6\uB2E4`);
|
|
37
|
+
}
|
|
38
|
+
const lc = L[i];
|
|
39
|
+
const uc = U === void 0 ? void 0 : U[i];
|
|
40
|
+
const cands = between(lc, uc);
|
|
41
|
+
if (cands.length > 0) {
|
|
42
|
+
if (uc === void 0) return L.slice(0, i) + cands[0];
|
|
43
|
+
return L.slice(0, i) + cands[Math.floor(cands.length / 2)];
|
|
44
|
+
}
|
|
45
|
+
for (let j = i + 1; j < L.length; j += 1) {
|
|
46
|
+
const up = between(L[j], void 0);
|
|
47
|
+
if (up.length > 0) return L.slice(0, j) + up[0];
|
|
48
|
+
}
|
|
49
|
+
return `${L}V`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// packages/plugin-tree/src/logic.ts
|
|
53
|
+
var PACKAGE_ID = "aic.tree";
|
|
54
|
+
var VERSION = "0.1.5";
|
|
55
|
+
var SELECTION_FORMAT = "aic.tree/selection-1";
|
|
56
|
+
var MEMO_ID = /^memo\d+$/;
|
|
57
|
+
var Reject = class extends Error {
|
|
58
|
+
constructor(code, message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.code = code;
|
|
61
|
+
}
|
|
62
|
+
code;
|
|
63
|
+
};
|
|
64
|
+
var all = (s, type) => Object.values(s.records).filter((r) => r.type === type);
|
|
65
|
+
var keyOf = (r) => sortKey(r.content.order, r.id);
|
|
66
|
+
var byKey = (a, b) => keyOf(a) < keyOf(b) ? -1 : 1;
|
|
67
|
+
var byIdNumber = (a, b) => {
|
|
68
|
+
const na = Number(a.id.replace(/\D/g, ""));
|
|
69
|
+
const nb = Number(b.id.replace(/\D/g, ""));
|
|
70
|
+
return na - nb || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
71
|
+
};
|
|
72
|
+
var node = (s, id) => s.records[id]?.content;
|
|
73
|
+
function rootOf(s) {
|
|
74
|
+
return all(s, "node").filter((r) => r.content.parent === null).sort(byIdNumber)[0];
|
|
75
|
+
}
|
|
76
|
+
function childrenOf(s, parent) {
|
|
77
|
+
return all(s, "node").filter((r) => r.content.parent === parent).sort(byKey);
|
|
78
|
+
}
|
|
79
|
+
function stickersOf(s, nodeId) {
|
|
80
|
+
return all(s, "sticker").filter((r) => r.content.node === nodeId).sort(byIdNumber);
|
|
81
|
+
}
|
|
82
|
+
function subtree(s, id) {
|
|
83
|
+
const out = [];
|
|
84
|
+
const seen = /* @__PURE__ */ new Set();
|
|
85
|
+
const walk = (x) => {
|
|
86
|
+
if (seen.has(x)) return;
|
|
87
|
+
seen.add(x);
|
|
88
|
+
out.push(x);
|
|
89
|
+
for (const c of childrenOf(s, x)) walk(c.id);
|
|
90
|
+
};
|
|
91
|
+
walk(id);
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
function ancestors(s, id) {
|
|
95
|
+
const out = [];
|
|
96
|
+
const seen = /* @__PURE__ */ new Set([id]);
|
|
97
|
+
let p = node(s, id)?.parent ?? null;
|
|
98
|
+
while (p !== null && s.records[p]?.type === "node" && !seen.has(p)) {
|
|
99
|
+
out.unshift(p);
|
|
100
|
+
seen.add(p);
|
|
101
|
+
p = node(s, p).parent;
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function need(s, id, type, what) {
|
|
106
|
+
if (typeof id !== "string" || id === "") throw new Reject("INVALID_INPUT", `${what} id is required`);
|
|
107
|
+
const r = s.records[id];
|
|
108
|
+
if (!r) throw new Reject("TARGET_NOT_FOUND", `${what} ${id} was not found`);
|
|
109
|
+
if (r.type !== type) throw new Reject("INVALID_INPUT", `${id} is not a ${what}`);
|
|
110
|
+
return r;
|
|
111
|
+
}
|
|
112
|
+
function titleInput(input, ctx) {
|
|
113
|
+
const v = input.title;
|
|
114
|
+
if (typeof v !== "string" || v.trim() === "") throw new Reject("INVALID_INPUT", "The title is empty");
|
|
115
|
+
if (ctx.tempNames.includes(v.trim())) throw new Reject("INVALID_INPUT", `"${v.trim()}" is the same as a temporary name in this request, so it cannot be used as text`);
|
|
116
|
+
return v.trim();
|
|
117
|
+
}
|
|
118
|
+
function afterInput(input) {
|
|
119
|
+
const v = input.after;
|
|
120
|
+
if (v === void 0 || v === null) return v;
|
|
121
|
+
if (typeof v !== "string") throw new Reject("INVALID_INPUT", "after must be the id of the previous sibling");
|
|
122
|
+
return v;
|
|
123
|
+
}
|
|
124
|
+
function newOrder(sibs, afterId, self) {
|
|
125
|
+
const list = sibs.filter((r) => r.id !== self);
|
|
126
|
+
let leftIdx;
|
|
127
|
+
if (afterId === void 0) leftIdx = list.length - 1;
|
|
128
|
+
else if (afterId === null) leftIdx = -1;
|
|
129
|
+
else {
|
|
130
|
+
leftIdx = list.findIndex((r) => r.id === afterId);
|
|
131
|
+
if (leftIdx < 0) throw new Reject("INVALID_INPUT", `${afterId} is not a sibling in the same place`);
|
|
132
|
+
}
|
|
133
|
+
const left = leftIdx >= 0 ? list[leftIdx] : void 0;
|
|
134
|
+
const right = list[leftIdx + 1];
|
|
135
|
+
const leftKey = left ? left.id.startsWith("$") ? boundAfterOrder(left.content.order) : keyOf(left) : void 0;
|
|
136
|
+
const rightKey = right ? right.id.startsWith("$") ? right.content.order : keyOf(right) : void 0;
|
|
137
|
+
return orderBetween(leftKey, rightKey);
|
|
138
|
+
}
|
|
139
|
+
var posRefs = (after) => typeof after === "string" ? { after } : void 0;
|
|
140
|
+
var label = (s, id) => s.records[id]?.type === "node" ? `(${id}) ${node(s, id).title}` : `(${id})`;
|
|
141
|
+
function parentInput(s, v) {
|
|
142
|
+
if (v === void 0 || v === null) {
|
|
143
|
+
const root = rootOf(s);
|
|
144
|
+
if (root) throw new Reject("INVALID_INPUT", `There is only one root. Root ${label(s, root.id)} already exists, so give a node id in parent`);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
return need(s, v, "node", "parent node").id;
|
|
148
|
+
}
|
|
149
|
+
function memoInput(s, input, ctx) {
|
|
150
|
+
const m = input.memo;
|
|
151
|
+
if (typeof m !== "string" || m === "") {
|
|
152
|
+
throw new Reject("INVALID_INPUT", "A memo is required for the sticker. Give a memo id from the memo box (memo3), or the temporary name ($name) given with as to core.memo.add in the same request");
|
|
153
|
+
}
|
|
154
|
+
if (MEMO_ID.test(m)) return m;
|
|
155
|
+
if (!m.startsWith("$") || !ctx.tempNames.includes(m)) {
|
|
156
|
+
throw new Reject("INVALID_INPUT", `${m} is not a memo. Give a memo id from the memo box (memo3), or the temporary name given with as to core.memo.add in the same request`);
|
|
157
|
+
}
|
|
158
|
+
if (s.records[m]) throw new Reject("INVALID_INPUT", `${m} is a ${s.records[m].type} in this tree. Give the temporary name of a memo`);
|
|
159
|
+
return m;
|
|
160
|
+
}
|
|
161
|
+
var OPERATIONS = {
|
|
162
|
+
"node.add": (s, input, id, ctx) => {
|
|
163
|
+
const parent = parentInput(s, input.parent);
|
|
164
|
+
const after = afterInput(input);
|
|
165
|
+
const title = titleInput(input, ctx);
|
|
166
|
+
const content = { parent, order: parent === null ? orderBetween() : newOrder(childrenOf(s, parent), after), title };
|
|
167
|
+
return {
|
|
168
|
+
changes: [{ id: id(0), type: "node", prefix: "n", after: content, refs: posRefs(after) }],
|
|
169
|
+
summary: parent === null ? `Root created (${id(0)}): ${title}` : `Node added (${id(0)}, under ${parent}): ${title}`
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
"node.update": (s, input, _id, ctx) => {
|
|
173
|
+
const r = need(s, input.node, "node", "node");
|
|
174
|
+
const c = r.content;
|
|
175
|
+
const title = titleInput(input, ctx);
|
|
176
|
+
const summary = title === c.title ? `Node ${r.id} (${c.title}): nothing changed` : `Node ${r.id} renamed from "${c.title}" to "${title}"`;
|
|
177
|
+
return { changes: [{ id: r.id, type: "node", after: { ...c, title } }], summary };
|
|
178
|
+
},
|
|
179
|
+
"node.move": (s, input) => {
|
|
180
|
+
const r = need(s, input.node, "node", "node");
|
|
181
|
+
const c = r.content;
|
|
182
|
+
if (c.parent === null) throw new Reject("INVALID_INPUT", "The root cannot be moved");
|
|
183
|
+
const parent = need(s, input.parent, "node", "new parent node").id;
|
|
184
|
+
if (subtree(s, r.id).includes(parent)) throw new Reject("INVALID_INPUT", `${parent} is ${r.id} itself or a node under it, so it cannot be moved there`);
|
|
185
|
+
const after = afterInput(input);
|
|
186
|
+
const next = { ...c, parent, order: newOrder(childrenOf(s, parent), after, r.id) };
|
|
187
|
+
const where = parent === c.parent ? "within the same parent" : `under ${label(s, parent)}`;
|
|
188
|
+
return {
|
|
189
|
+
changes: [{ id: r.id, type: "node", after: next, refs: posRefs(after), moved: true }],
|
|
190
|
+
summary: `Moved (${r.id} ${c.title}): ${where}${after ? `, after ${after}` : after === null ? ", to the front" : ""}`
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
// 스티커는 자동으로 떨어지지 않는다(999 2.1절). 지운 노드에 붙은 스티커는 남아 지워진 노드를 가리킨다.
|
|
194
|
+
"node.remove": (s, input) => {
|
|
195
|
+
const r = need(s, input.node, "node", "node");
|
|
196
|
+
const c = r.content;
|
|
197
|
+
if (c.parent === null) throw new Reject("INVALID_INPUT", "The root cannot be removed. If its name changed, fix it with node.update");
|
|
198
|
+
const ids = subtree(s, r.id);
|
|
199
|
+
const stuck = all(s, "sticker").filter((x) => ids.includes(x.content.node)).length;
|
|
200
|
+
return {
|
|
201
|
+
changes: ids.map((x) => ({ id: x, type: "node", after: null })),
|
|
202
|
+
summary: `Node removed (${r.id}): ${c.title}${ids.length > 1 ? `, with ${ids.length - 1} node(s) under it` : ""}${stuck ? `. ${stuck} sticker(s) that were on it stay` : ""}`
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
"sticker.add": (s, input, id, ctx) => {
|
|
206
|
+
const memo = memoInput(s, input, ctx);
|
|
207
|
+
const target = need(s, input.node, "node", "target node").id;
|
|
208
|
+
const twin = all(s, "sticker").find((x) => x.content.memo === memo && x.content.node === target);
|
|
209
|
+
if (twin) throw new Reject("INVALID_INPUT", `Memo ${memo} is already on ${label(s, target)} as sticker ${twin.id}`);
|
|
210
|
+
return {
|
|
211
|
+
changes: [{ id: id(0), type: "sticker", prefix: "st", after: { memo, node: target } }],
|
|
212
|
+
summary: `Sticker added (${id(0)}): memo ${memo} on ${label(s, target)}`
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
"sticker.attach": (s, input) => {
|
|
216
|
+
const r = need(s, input.sticker, "sticker", "sticker");
|
|
217
|
+
const c = r.content;
|
|
218
|
+
const target = need(s, input.node, "node", "target node").id;
|
|
219
|
+
return { changes: [{ id: r.id, type: "sticker", after: { ...c, node: target } }], summary: `Sticker moved (${r.id}): to ${label(s, target)}` };
|
|
220
|
+
},
|
|
221
|
+
"sticker.remove": (s, input) => {
|
|
222
|
+
const r = need(s, input.sticker, "sticker", "sticker");
|
|
223
|
+
return { changes: [{ id: r.id, type: "sticker", after: null }], summary: `Sticker removed (${r.id}). Memo ${r.content.memo} stays in the memo box` };
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function refsOf(r) {
|
|
227
|
+
const out = [];
|
|
228
|
+
const add = (to, kind, soft = false) => {
|
|
229
|
+
if (to) out.push({ from: r.id, to, kind, ...soft ? { soft: true } : {} });
|
|
230
|
+
};
|
|
231
|
+
if (r.type === "node") add(r.content.parent, "parent");
|
|
232
|
+
else if (r.type === "sticker") {
|
|
233
|
+
const c = r.content;
|
|
234
|
+
add(c.memo, "sticker_memo", true);
|
|
235
|
+
add(c.node, "sticker_node", true);
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
function validate(candidate, changed) {
|
|
240
|
+
const out = [];
|
|
241
|
+
const err = (record, code, message) => out.push({ level: "error", code, record, message });
|
|
242
|
+
const changedSet = new Set(changed);
|
|
243
|
+
let structural = false;
|
|
244
|
+
for (const id of changed) {
|
|
245
|
+
const r = candidate.records[id];
|
|
246
|
+
if (!r) continue;
|
|
247
|
+
if (r.type === "node") structural = true;
|
|
248
|
+
for (const ref of refsOf(r)) {
|
|
249
|
+
if (ref.kind === "sticker_memo") continue;
|
|
250
|
+
const to = candidate.records[ref.to];
|
|
251
|
+
if (!to) err(id, "dangling_ref", `${ref.to}, which ${id} points to, does not exist`);
|
|
252
|
+
else if (to.type !== "node") err(id, "wrong_ref_type", `${ref.kind} of ${id} must point to a node, but ${ref.to} is a ${to.type}`);
|
|
253
|
+
}
|
|
254
|
+
if (r.type === "sticker" && !MEMO_ID.test(r.content.memo)) {
|
|
255
|
+
err(id, "sticker_not_memo", `Sticker ${id} must point to a memo in the memo box`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (structural) {
|
|
259
|
+
const nodes = all(candidate, "node");
|
|
260
|
+
const roots = nodes.filter((t) => t.content.parent === null);
|
|
261
|
+
if (roots.length > 1) err(roots.map((t) => t.id).find((x) => changedSet.has(x)) ?? roots[1].id, "second_root", `There is only one root: ${roots.map((t) => t.id).join(", ")}`);
|
|
262
|
+
for (const t of nodes) {
|
|
263
|
+
if (!changedSet.has(t.id)) continue;
|
|
264
|
+
const seen = /* @__PURE__ */ new Set([t.id]);
|
|
265
|
+
let p = t.content.parent;
|
|
266
|
+
while (p !== null && candidate.records[p]?.type === "node") {
|
|
267
|
+
if (seen.has(p)) {
|
|
268
|
+
err(t.id, "containment_cycle", `The parent chain of ${t.id} loops`);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
seen.add(p);
|
|
272
|
+
p = candidate.records[p].content.parent;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const gone = changed.filter((id) => !candidate.records[id]);
|
|
277
|
+
if (gone.length > 0) {
|
|
278
|
+
const goneSet = new Set(gone);
|
|
279
|
+
for (const r of Object.values(candidate.records)) {
|
|
280
|
+
if (changedSet.has(r.id)) continue;
|
|
281
|
+
for (const ref of refsOf(r)) if (!ref.soft && goneSet.has(ref.to)) err(r.id, "dangling_ref", `${r.id} points to ${ref.to}, which was removed`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
286
|
+
function nodeScope(s, scope) {
|
|
287
|
+
const ids = scope?.targets ?? (scope?.target !== void 0 ? [scope.target] : null);
|
|
288
|
+
if (ids === null) return null;
|
|
289
|
+
for (const id of ids) {
|
|
290
|
+
const r = s.records[id];
|
|
291
|
+
if (!r) throw new Reject("TARGET_NOT_FOUND", `Node ${id} was not found`);
|
|
292
|
+
if (r.type !== "node") throw new Reject("INVALID_INPUT", `The scope for a narrowed read is a node id. ${id} is a ${r.type}`);
|
|
293
|
+
}
|
|
294
|
+
return ids;
|
|
295
|
+
}
|
|
296
|
+
function viewOf(s, ids) {
|
|
297
|
+
if (ids === null) return { full: new Set(all(s, "node").map((t) => t.id)), heads: /* @__PURE__ */ new Set() };
|
|
298
|
+
const full = new Set(ids.flatMap((id) => subtree(s, id)));
|
|
299
|
+
const heads = new Set(ids.flatMap((id) => ancestors(s, id)).filter((x) => !full.has(x)));
|
|
300
|
+
return { full, heads };
|
|
301
|
+
}
|
|
302
|
+
var orphanStickers = (s) => all(s, "sticker").sort(byIdNumber).filter((x) => s.records[x.content.node]?.type !== "node");
|
|
303
|
+
function conceptText(s, ids, mine) {
|
|
304
|
+
const starred = new Set(mine.flatMap((m) => m.changes.filter((c) => c.after !== null).map((c) => c.record)));
|
|
305
|
+
const star = (id) => starred.has(id) ? " *" : "";
|
|
306
|
+
const root = rootOf(s);
|
|
307
|
+
if (!root) return "The tree is empty. Write the topic the person gave as the root with node.add (without parent).";
|
|
308
|
+
const v = viewOf(s, ids);
|
|
309
|
+
const lines = [];
|
|
310
|
+
const stickerLines = (id, pad) => {
|
|
311
|
+
for (const x of stickersOf(s, id)) lines.push(`${pad}Sticker (${x.id})${star(x.id)}: memo ${x.content.memo}`);
|
|
312
|
+
};
|
|
313
|
+
const nodeBlock = (id, depth) => {
|
|
314
|
+
const c = node(s, id);
|
|
315
|
+
const pad = " ".repeat(Math.max(0, depth - 1));
|
|
316
|
+
const inner = depth === 0 ? " " : `${pad} `;
|
|
317
|
+
lines.push(depth === 0 ? `Root (${id})${star(id)} ${c.title}` : `${pad}- (${id})${star(id)} ${c.title}`);
|
|
318
|
+
stickerLines(id, inner);
|
|
319
|
+
for (const k of childrenOf(s, id)) nodeBlock(k.id, depth + 1);
|
|
320
|
+
};
|
|
321
|
+
if (ids === null) nodeBlock(root.id, 0);
|
|
322
|
+
else {
|
|
323
|
+
lines.push("Nodes above");
|
|
324
|
+
for (const h of [...v.heads].sort((a, b) => ancestors(s, a).length - ancestors(s, b).length)) lines.push(`- (${h})${star(h)} ${node(s, h).title}`);
|
|
325
|
+
for (const id of ids) {
|
|
326
|
+
lines.push("", `Node being read (${id})`);
|
|
327
|
+
nodeBlock(id, 1);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const orphans = orphanStickers(s);
|
|
331
|
+
if (orphans.length) {
|
|
332
|
+
lines.push("", "Stickers left on removed nodes");
|
|
333
|
+
for (const x of orphans) {
|
|
334
|
+
const c = x.content;
|
|
335
|
+
lines.push(`- Sticker (${x.id})${star(x.id)}: memo ${c.memo}, removed node ${c.node}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return lines.join("\n");
|
|
339
|
+
}
|
|
340
|
+
function scopeRecords(s, ids) {
|
|
341
|
+
const v = viewOf(s, ids);
|
|
342
|
+
const out = /* @__PURE__ */ new Set([...v.full, ...v.heads]);
|
|
343
|
+
for (const id of v.full) for (const x of stickersOf(s, id)) out.add(x.id);
|
|
344
|
+
return [...out];
|
|
345
|
+
}
|
|
346
|
+
function project(s, scope, mine) {
|
|
347
|
+
const ids = nodeScope(s, scope);
|
|
348
|
+
const root = rootOf(s);
|
|
349
|
+
return {
|
|
350
|
+
text: conceptText(s, ids, mine),
|
|
351
|
+
scopeLabel: ids ? `Read nodes ${ids.join(", ")} and everything under them, the nodes above up to the root, and the stickers on them` : "Read everything",
|
|
352
|
+
// 화면은 한 번에 받아 트리를 그린다. 좁혀 읽어도 JSON 은 전체다
|
|
353
|
+
json: {
|
|
354
|
+
root: root?.id ?? null,
|
|
355
|
+
nodes: all(s, "node").sort(byKey).map((r) => ({ id: r.id, ...r.content })),
|
|
356
|
+
stickers: all(s, "sticker").sort(byIdNumber).map((r) => ({ id: r.id, ...r.content }))
|
|
357
|
+
},
|
|
358
|
+
...ids ? { records: scopeRecords(s, ids) } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function resolveLabel(s, id) {
|
|
362
|
+
const r = s.records[id];
|
|
363
|
+
if (!r) return id;
|
|
364
|
+
if (r.type === "node") return `Node ${id}: ${r.content.title}`;
|
|
365
|
+
if (r.type === "sticker") return `Sticker ${id}: memo ${r.content.memo}`;
|
|
366
|
+
return id;
|
|
367
|
+
}
|
|
368
|
+
var idList = (v) => Array.isArray(v) && v.length <= 2e3 && v.every((x) => typeof x === "string");
|
|
369
|
+
function selectionProblem(v) {
|
|
370
|
+
const x = v;
|
|
371
|
+
if (typeof x !== "object" || x === null || x.format !== SELECTION_FORMAT) return `The format of the selection is not ${SELECTION_FORMAT}`;
|
|
372
|
+
if (typeof x.rev !== "string") return "The selection has no revision it was drawn from (rev)";
|
|
373
|
+
if (!idList(x.nodes)) return "nodes of the selection must be a list of node ids";
|
|
374
|
+
if (x.collapsed !== void 0 && !idList(x.collapsed)) return "collapsed of the selection must be a list of node ids";
|
|
375
|
+
if (x.labels !== void 0 && (typeof x.labels !== "object" || x.labels === null || Array.isArray(x.labels))) return "labels of the selection must be an object from id to text";
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
var MAX_SELECTION_LINES = 60;
|
|
379
|
+
var MAX_NAMED_CHILDREN = 12;
|
|
380
|
+
var many = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
381
|
+
function describeSelection(s, input) {
|
|
382
|
+
const problem = selectionProblem(input?.selection);
|
|
383
|
+
if (problem) return { error: "INVALID_INPUT", summary: problem };
|
|
384
|
+
const sel = input.selection;
|
|
385
|
+
const targets = [];
|
|
386
|
+
const gone = [];
|
|
387
|
+
const lines = [];
|
|
388
|
+
const now = typeof input.current === "string" && input.current !== sel.rev ? ` Something changed after that (now ${input.current}). What follows is the current state.` : "";
|
|
389
|
+
lines.push(`Revision when selected: ${sel.rev}.${now}`);
|
|
390
|
+
const folded = new Set(sel.collapsed ?? []);
|
|
391
|
+
if (sel.nodes.length === 0) {
|
|
392
|
+
const root = rootOf(s);
|
|
393
|
+
lines.push(root ? `No node is selected. The words are about the whole tree (root ${label(s, root.id)}).` : "No node is selected. The tree is empty.");
|
|
394
|
+
} else lines.push(`Selected nodes (${sel.nodes.length}):`);
|
|
395
|
+
for (const id of sel.nodes.slice(0, MAX_SELECTION_LINES)) {
|
|
396
|
+
if (s.records[id]?.type !== "node") {
|
|
397
|
+
gone.push(id);
|
|
398
|
+
lines.push(`- (${id}) ${sel.labels?.[id] ?? "name unknown"} (removed since)`);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
targets.push(id);
|
|
402
|
+
const c = node(s, id);
|
|
403
|
+
const path = [...ancestors(s, id), id].map((x) => node(s, x).title).join(" > ");
|
|
404
|
+
const kids = childrenOf(s, id);
|
|
405
|
+
const below = subtree(s, id).length - 1;
|
|
406
|
+
const parts = [`- (${id}) ${c.title}: ${c.parent === null ? "it is the root" : `path ${path}`}.`];
|
|
407
|
+
if (below === 0) parts.push("It has no nodes under it.");
|
|
408
|
+
else {
|
|
409
|
+
const named = kids.slice(0, MAX_NAMED_CHILDREN).map((k) => label(s, k.id)).join(", ");
|
|
410
|
+
parts.push(`${many(below, "node")} under it (${kids.length} directly under: ${named}${kids.length > MAX_NAMED_CHILDREN ? ` and ${kids.length - MAX_NAMED_CHILDREN} more` : ""}).`);
|
|
411
|
+
if (folded.has(id)) parts.push("It was collapsed on the person's screen, so the nodes under it were not visible.");
|
|
412
|
+
}
|
|
413
|
+
const sts = stickersOf(s, id);
|
|
414
|
+
if (sts.length) parts.push(`Stickers on it: ${sts.map((x) => `(${x.id}) memo ${x.content.memo}`).join(", ")}. Read the memo text in the memo box.`);
|
|
415
|
+
lines.push(parts.join(" "));
|
|
416
|
+
}
|
|
417
|
+
if (sel.nodes.length > MAX_SELECTION_LINES) lines.push(`- and ${sel.nodes.length - MAX_SELECTION_LINES} more. Read them with a node id in scope`);
|
|
418
|
+
if (sel.nodes.length > 1) lines.push("More than one node is selected. If it is not clear which one the person means, ask the person.");
|
|
419
|
+
return { text: lines.join("\n"), targets, gone };
|
|
420
|
+
}
|
|
421
|
+
var AI_GUIDE = [
|
|
422
|
+
"This screen splits nodes that have only a name into a tree. You add stickers to nodes to write down thoughts.",
|
|
423
|
+
"Write the topic the person gave as the name of the root, in the meaning you understood, and split it into nodes under the root. The person can add, move and remove nodes at any time. Do not hold on to the shape you made first.",
|
|
424
|
+
"A node has only a name. Do not write explanations, reasons, things to do or questions in a node. Add them as stickers.",
|
|
425
|
+
"The body of a sticker is a memo in the core memo box, and the sticker itself has no text. To put a memo that is already in the memo box on a node, give its memo id (memo3) as memo in sticker.add. Do not make a new memo with the same text as a copy. To write a new thought and add it, make the memo with core.memo.add in the same request (give a $name with as), and give that $name as memo in sticker.add. You can send several sticker.add in one request to sort several memos at once. The same memo can go on other nodes too, but not twice on the same node.",
|
|
426
|
+
"Ask the person before you add or remove a sticker. Stickers are never added or removed automatically. When a sticker is removed, its memo stays in the memo box. Change the text of a memo with core.memo.update.",
|
|
427
|
+
"When a node is removed, the stickers on it stay and point to the removed node. If a sticker will be used again, move it to another node with sticker.attach. If not, ask the person and remove it.",
|
|
428
|
+
"Write content in the language the person uses.",
|
|
429
|
+
"For a narrowed read, use a node id as scope.",
|
|
430
|
+
"When the person selects nodes on the screen and sends them with words, read them with read_selection. The description is the tree the person sees now. If a node was collapsed when the person selected it, the person spoke without seeing the nodes under it."
|
|
431
|
+
].join(" ");
|
|
432
|
+
var DESCRIPTION = {
|
|
433
|
+
id: PACKAGE_ID,
|
|
434
|
+
version: VERSION,
|
|
435
|
+
title: "Tree",
|
|
436
|
+
aiGuide: AI_GUIDE,
|
|
437
|
+
markGuide: 'A node name is plain text. Do not use marks in the text. For something new made in the same request, give a $name with "as" and point to it in the input of other operations.',
|
|
438
|
+
operations: [
|
|
439
|
+
{
|
|
440
|
+
op: "node.add",
|
|
441
|
+
input: { parent: "Parent node id or $name. Leave it out only when making the root", after: "Id of the previous sibling. null for the front, leave it out for the end", title: "Name" },
|
|
442
|
+
summary: "Makes a node. There is only one root",
|
|
443
|
+
example: [
|
|
444
|
+
{ op: "node.add", as: "$root", input: { title: "First release" } },
|
|
445
|
+
{ op: "node.add", input: { parent: "$root", title: "Installer" } }
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
{ op: "node.update", input: { node: "Node id", title: "New name" }, summary: "Changes the name. The id stays the same" },
|
|
449
|
+
{ op: "node.move", input: { node: "Node id", parent: "New parent node id", after: "Id of the previous sibling. null for the front, leave it out for the end" }, summary: "Moves a node under another parent or within the same parent. The id stays the same" },
|
|
450
|
+
{ op: "node.remove", input: { node: "Node id" }, summary: "Removes a node and everything under it. Stickers that were on it stay. The root cannot be removed" },
|
|
451
|
+
{
|
|
452
|
+
op: "sticker.add",
|
|
453
|
+
input: { memo: "Memo id from the memo box (memo3), or the $name of a memo made with core.memo.add in the same request", node: "Id or $name of the node to add it to" },
|
|
454
|
+
summary: "Adds a sticker to a node. Add a memo that already exists, or make a new memo in the same request and add it. Ask the person first",
|
|
455
|
+
example: [
|
|
456
|
+
{ op: "sticker.add", input: { memo: "memo3", node: "n2" } },
|
|
457
|
+
{ op: "sticker.add", input: { memo: "memo7", node: "n4" } },
|
|
458
|
+
{ op: "core.memo.add", as: "$m", input: { text: "We do not know yet if the installer needs a signature" } },
|
|
459
|
+
{ op: "sticker.add", input: { memo: "$m", node: "n2" } }
|
|
460
|
+
]
|
|
461
|
+
},
|
|
462
|
+
{ op: "sticker.attach", input: { sticker: "Sticker id", node: "Id of the node to move it to" }, summary: "Moves a sticker to another node" },
|
|
463
|
+
{ op: "sticker.remove", input: { sticker: "Sticker id" }, summary: "Removes a sticker. The memo stays in the memo box" }
|
|
464
|
+
]
|
|
465
|
+
};
|
|
466
|
+
var run = (f) => {
|
|
467
|
+
try {
|
|
468
|
+
return f();
|
|
469
|
+
} catch (e) {
|
|
470
|
+
if (e instanceof Reject) return { error: e.code, summary: e.message };
|
|
471
|
+
throw e;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
var logic = {
|
|
475
|
+
describe: () => DESCRIPTION,
|
|
476
|
+
initialize: () => [],
|
|
477
|
+
plan(state, op, ctx) {
|
|
478
|
+
const handler = OPERATIONS[op.op];
|
|
479
|
+
if (!handler) return { error: "INVALID_INPUT", summary: `Unknown operation ${op.op}. See the list of operations with describe_document` };
|
|
480
|
+
const id = (k) => k === 0 && op.as ? op.as : `$~${ctx.stepIndex}.${k}`;
|
|
481
|
+
return run(() => {
|
|
482
|
+
const out = handler(state, op.input ?? {}, id, ctx);
|
|
483
|
+
return { ...out, summary: /[.?!]$/.test(out.summary) ? out.summary : `${out.summary}.` };
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
validate,
|
|
487
|
+
project: (state, scope, mine) => run(() => project(state, scope, mine)),
|
|
488
|
+
extractRefs: refsOf,
|
|
489
|
+
prepareGeneration: () => ({ error: "UNSUPPORTED_CAPABILITY", summary: "The tree does not make output" }),
|
|
490
|
+
interpretSelection(state, sel) {
|
|
491
|
+
const text = sel.text.trim();
|
|
492
|
+
const candidates = text === "" ? [] : all(state, "node").sort(byIdNumber).filter((t) => {
|
|
493
|
+
const title = t.content.title;
|
|
494
|
+
return title !== "" && (text.includes(title) || title.includes(text));
|
|
495
|
+
}).map((t) => ({ id: t.id, label: resolveLabel(state, t.id), why: "The selected text overlaps the node name" }));
|
|
496
|
+
return { candidates };
|
|
497
|
+
},
|
|
498
|
+
resolveTarget(state, target) {
|
|
499
|
+
const r = state.records[target.id];
|
|
500
|
+
return r ? { found: true, label: resolveLabel(state, r.id) } : { found: false };
|
|
501
|
+
},
|
|
502
|
+
describeSelection
|
|
503
|
+
};
|
|
504
|
+
globalThis.__aicPlugin = logic;
|
|
505
|
+
})();
|