@aopslab/domain-ops-docman 0.1.4
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 +202 -0
- package/NOTICE +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/runner.d.ts +1 -0
- package/dist/runner.js +324 -0
- package/dist/specs.d.ts +2 -0
- package/dist/specs.js +342 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +35 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runDocmanTool(toolId: string, input: unknown): Promise<unknown>;
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { Effect } from 'effect';
|
|
4
|
+
import { config as loadDotEnv } from 'dotenv';
|
|
5
|
+
import { createDocmanKitWithEnv, getDocmanKitEnvConfig } from '@aopslab/domain-kit-docman';
|
|
6
|
+
const TOOL_DOCUMENT_DELETE_SAFE = 'docman-document-delete-safe';
|
|
7
|
+
const TOOL_DOCUMENT_VERSION_DELETE_SAFE = 'docman-document-version-delete-safe';
|
|
8
|
+
const TOOL_DOCUMENT_SECTION_LINK_USAGE_LIST = 'docman-document-section-link-usage-list';
|
|
9
|
+
const TOOL_DOCUMENT_COMPOSE_INDEX = 'docman-document-compose-index';
|
|
10
|
+
const TOOL_DOCUMENT_INDEX_BUILD = 'docman-document-index-build';
|
|
11
|
+
const TOOL_DOCUMENT_INDEX_GET = 'docman-document-index-get';
|
|
12
|
+
const TOOL_DOCUMENT_SUMMARY_BUILD = 'docman-document-summary-build';
|
|
13
|
+
const TOOL_DOCUMENT_SUMMARY_GET = 'docman-document-summary-get';
|
|
14
|
+
const TOOL_DOCUMENT_SEARCH = 'docman-document-search';
|
|
15
|
+
const TOOL_DOCUMENT_ANSWER_PACK = 'docman-document-answer-pack';
|
|
16
|
+
const TOOL_DOCUMENT_COMPOSE_FETCH = 'docman-document-compose-fetch';
|
|
17
|
+
let envLoaded = false;
|
|
18
|
+
let cachedServices = null;
|
|
19
|
+
function normalizeNonEmpty(value) {
|
|
20
|
+
if (typeof value !== 'string')
|
|
21
|
+
return undefined;
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
24
|
+
}
|
|
25
|
+
function normalizePositiveInt(value) {
|
|
26
|
+
if (value === undefined || value === null)
|
|
27
|
+
return undefined;
|
|
28
|
+
const parsed = Number(value);
|
|
29
|
+
if (!Number.isInteger(parsed) || parsed <= 0)
|
|
30
|
+
return undefined;
|
|
31
|
+
return parsed;
|
|
32
|
+
}
|
|
33
|
+
function normalizeRetrievalStrategy(value) {
|
|
34
|
+
const normalized = normalizeNonEmpty(value);
|
|
35
|
+
if (normalized === 'hybrid' || normalized === 'semantic' || normalized === 'lexical') {
|
|
36
|
+
return normalized;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function pickLocaleOptions(payload) {
|
|
41
|
+
const locale = normalizeNonEmpty(payload.locale);
|
|
42
|
+
const fallbackLocale = normalizeNonEmpty(payload.fallbackLocale);
|
|
43
|
+
return {
|
|
44
|
+
...(locale ? { locale } : {}),
|
|
45
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function toRecord(input) {
|
|
49
|
+
if (!input || typeof input !== 'object')
|
|
50
|
+
return {};
|
|
51
|
+
return input;
|
|
52
|
+
}
|
|
53
|
+
function loadEnvOnce() {
|
|
54
|
+
if (envLoaded)
|
|
55
|
+
return;
|
|
56
|
+
envLoaded = true;
|
|
57
|
+
const candidates = [
|
|
58
|
+
process.env.DOTENV_CONFIG_PATH,
|
|
59
|
+
process.env.DOCMAN_ENV_PATH,
|
|
60
|
+
path.resolve(process.cwd(), '.env'),
|
|
61
|
+
path.resolve(process.cwd(), '..', '.env'),
|
|
62
|
+
path.resolve(process.cwd(), '../..', '.env'),
|
|
63
|
+
].filter(Boolean);
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
if (!candidate)
|
|
66
|
+
continue;
|
|
67
|
+
if (!fs.existsSync(candidate))
|
|
68
|
+
continue;
|
|
69
|
+
loadDotEnv({ path: candidate, quiet: true });
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseToolId(toolId) {
|
|
74
|
+
const match = /^docman-(.+)-(list|get|create|update|delete)$/.exec(toolId);
|
|
75
|
+
if (!match)
|
|
76
|
+
return null;
|
|
77
|
+
return { entity: match[1], op: match[2] };
|
|
78
|
+
}
|
|
79
|
+
function toPascalCase(value) {
|
|
80
|
+
return value
|
|
81
|
+
.split('-')
|
|
82
|
+
.filter(Boolean)
|
|
83
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
84
|
+
.join('');
|
|
85
|
+
}
|
|
86
|
+
function toCamelCase(value) {
|
|
87
|
+
if (!value)
|
|
88
|
+
return value;
|
|
89
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
90
|
+
}
|
|
91
|
+
function buildServiceKey(entity) {
|
|
92
|
+
return `${toCamelCase(toPascalCase(entity))}Service`;
|
|
93
|
+
}
|
|
94
|
+
function buildListMethod(entity) {
|
|
95
|
+
return `list${toPascalCase(entity)}s`;
|
|
96
|
+
}
|
|
97
|
+
function buildUpdateMethod(entity) {
|
|
98
|
+
return `update${toPascalCase(entity)}`;
|
|
99
|
+
}
|
|
100
|
+
function buildRemoveMethod(entity) {
|
|
101
|
+
return `remove${toPascalCase(entity)}`;
|
|
102
|
+
}
|
|
103
|
+
async function getServices() {
|
|
104
|
+
if (cachedServices)
|
|
105
|
+
return cachedServices;
|
|
106
|
+
cachedServices = (async () => {
|
|
107
|
+
loadEnvOnce();
|
|
108
|
+
const envConfig = getDocmanKitEnvConfig();
|
|
109
|
+
const { kit } = createDocmanKitWithEnv({
|
|
110
|
+
envConfig,
|
|
111
|
+
baseContext: { tenantId: envConfig.tenantId },
|
|
112
|
+
});
|
|
113
|
+
const services = await kit.createAll();
|
|
114
|
+
return services;
|
|
115
|
+
})();
|
|
116
|
+
return cachedServices;
|
|
117
|
+
}
|
|
118
|
+
export async function runDocmanTool(toolId, input) {
|
|
119
|
+
const payload = toRecord(input);
|
|
120
|
+
const id = normalizeNonEmpty(payload.id);
|
|
121
|
+
if (toolId === TOOL_DOCUMENT_DELETE_SAFE) {
|
|
122
|
+
if (!id)
|
|
123
|
+
throw new Error('missing_required_id');
|
|
124
|
+
const confirmName = normalizeNonEmpty(payload.confirmName);
|
|
125
|
+
if (!confirmName)
|
|
126
|
+
throw new Error('missing_required_confirm_name');
|
|
127
|
+
const services = await getServices();
|
|
128
|
+
const service = services.documentService;
|
|
129
|
+
if (!service || typeof service.removeDocumentSafe !== 'function') {
|
|
130
|
+
throw new Error('docman_method_missing: documentService.removeDocumentSafe');
|
|
131
|
+
}
|
|
132
|
+
return Effect.runPromise(service.removeDocumentSafe(id, confirmName));
|
|
133
|
+
}
|
|
134
|
+
if (toolId === TOOL_DOCUMENT_VERSION_DELETE_SAFE) {
|
|
135
|
+
if (!id)
|
|
136
|
+
throw new Error('missing_required_id');
|
|
137
|
+
const services = await getServices();
|
|
138
|
+
const service = services.documentVersionService;
|
|
139
|
+
if (!service || typeof service.removeDocumentVersionSafe !== 'function') {
|
|
140
|
+
throw new Error('docman_method_missing: documentVersionService.removeDocumentVersionSafe');
|
|
141
|
+
}
|
|
142
|
+
return Effect.runPromise(service.removeDocumentVersionSafe(id));
|
|
143
|
+
}
|
|
144
|
+
if (toolId === TOOL_DOCUMENT_SECTION_LINK_USAGE_LIST) {
|
|
145
|
+
const sectionId = normalizeNonEmpty(payload.sectionId);
|
|
146
|
+
if (!sectionId) {
|
|
147
|
+
throw new Error('missing_required_section_id');
|
|
148
|
+
}
|
|
149
|
+
const services = await getServices();
|
|
150
|
+
const service = services.documentSectionLinkService;
|
|
151
|
+
if (!service || typeof service.listDocumentSectionLinkUsageBySectionId !== 'function') {
|
|
152
|
+
throw new Error('docman_method_missing: documentSectionLinkService.listDocumentSectionLinkUsageBySectionId');
|
|
153
|
+
}
|
|
154
|
+
return Effect.runPromise(service.listDocumentSectionLinkUsageBySectionId(sectionId));
|
|
155
|
+
}
|
|
156
|
+
if (toolId === TOOL_DOCUMENT_COMPOSE_INDEX) {
|
|
157
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
158
|
+
if (!documentVersionId)
|
|
159
|
+
throw new Error('missing_required_document_version_id');
|
|
160
|
+
const services = await getServices();
|
|
161
|
+
const service = services.documentService;
|
|
162
|
+
if (!service || typeof service.buildDocumentIndex !== 'function') {
|
|
163
|
+
throw new Error('docman_method_missing: documentService.buildDocumentIndex');
|
|
164
|
+
}
|
|
165
|
+
return Effect.runPromise(service.buildDocumentIndex(documentVersionId, pickLocaleOptions(payload)));
|
|
166
|
+
}
|
|
167
|
+
if (toolId === TOOL_DOCUMENT_INDEX_BUILD || toolId === TOOL_DOCUMENT_INDEX_GET) {
|
|
168
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
169
|
+
if (!documentVersionId)
|
|
170
|
+
throw new Error('missing_required_document_version_id');
|
|
171
|
+
const services = await getServices();
|
|
172
|
+
const service = services.documentService;
|
|
173
|
+
const methodName = toolId === TOOL_DOCUMENT_INDEX_BUILD ? 'buildPersistedDocumentIndex' : 'getPersistedDocumentIndex';
|
|
174
|
+
if (!service || typeof service[methodName] !== 'function') {
|
|
175
|
+
throw new Error(`docman_method_missing: documentService.${methodName}`);
|
|
176
|
+
}
|
|
177
|
+
return Effect.runPromise(service[methodName]({
|
|
178
|
+
documentVersionId,
|
|
179
|
+
...pickLocaleOptions(payload),
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
if (toolId === TOOL_DOCUMENT_SUMMARY_BUILD || toolId === TOOL_DOCUMENT_SUMMARY_GET) {
|
|
183
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
184
|
+
if (!documentVersionId)
|
|
185
|
+
throw new Error('missing_required_document_version_id');
|
|
186
|
+
const services = await getServices();
|
|
187
|
+
const service = services.documentService;
|
|
188
|
+
const methodName = toolId === TOOL_DOCUMENT_SUMMARY_BUILD ? 'buildPersistedDocumentSummary' : 'getPersistedDocumentSummary';
|
|
189
|
+
if (!service || typeof service[methodName] !== 'function') {
|
|
190
|
+
throw new Error(`docman_method_missing: documentService.${methodName}`);
|
|
191
|
+
}
|
|
192
|
+
return Effect.runPromise(service[methodName]({
|
|
193
|
+
documentVersionId,
|
|
194
|
+
...pickLocaleOptions(payload),
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
if (toolId === TOOL_DOCUMENT_SEARCH) {
|
|
198
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
199
|
+
if (!documentVersionId)
|
|
200
|
+
throw new Error('missing_required_document_version_id');
|
|
201
|
+
const q = normalizeNonEmpty(payload.q);
|
|
202
|
+
if (!q)
|
|
203
|
+
throw new Error('missing_required_q');
|
|
204
|
+
const services = await getServices();
|
|
205
|
+
const service = services.documentService;
|
|
206
|
+
if (!service || typeof service.searchPersistedDocumentIndex !== 'function') {
|
|
207
|
+
throw new Error('docman_method_missing: documentService.searchPersistedDocumentIndex');
|
|
208
|
+
}
|
|
209
|
+
const parsedLimit = Number(payload.limit);
|
|
210
|
+
const limit = Number.isInteger(parsedLimit) && parsedLimit > 0 ? parsedLimit : undefined;
|
|
211
|
+
const retrievalStrategy = normalizeRetrievalStrategy(payload.retrievalStrategy);
|
|
212
|
+
return Effect.runPromise(service.searchPersistedDocumentIndex({
|
|
213
|
+
documentVersionId,
|
|
214
|
+
q,
|
|
215
|
+
...(limit ? { limit } : {}),
|
|
216
|
+
...(retrievalStrategy ? { retrievalStrategy } : {}),
|
|
217
|
+
...pickLocaleOptions(payload),
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
if (toolId === TOOL_DOCUMENT_ANSWER_PACK) {
|
|
221
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
222
|
+
if (!documentVersionId)
|
|
223
|
+
throw new Error('missing_required_document_version_id');
|
|
224
|
+
const q = normalizeNonEmpty(payload.q);
|
|
225
|
+
if (!q)
|
|
226
|
+
throw new Error('missing_required_q');
|
|
227
|
+
const services = await getServices();
|
|
228
|
+
const service = services.documentService;
|
|
229
|
+
if (!service || typeof service.getDocumentAnswerPack !== 'function') {
|
|
230
|
+
throw new Error('docman_method_missing: documentService.getDocumentAnswerPack');
|
|
231
|
+
}
|
|
232
|
+
const parsedLimit = Number(payload.limit);
|
|
233
|
+
const limit = Number.isInteger(parsedLimit) && parsedLimit > 0 ? parsedLimit : undefined;
|
|
234
|
+
const retrievalStrategy = normalizeRetrievalStrategy(payload.retrievalStrategy);
|
|
235
|
+
return Effect.runPromise(service.getDocumentAnswerPack({
|
|
236
|
+
documentVersionId,
|
|
237
|
+
q,
|
|
238
|
+
...(limit ? { limit } : {}),
|
|
239
|
+
...(retrievalStrategy ? { retrievalStrategy } : {}),
|
|
240
|
+
...pickLocaleOptions(payload),
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
if (toolId === TOOL_DOCUMENT_COMPOSE_FETCH) {
|
|
244
|
+
const documentVersionId = normalizeNonEmpty(payload.documentVersionId);
|
|
245
|
+
if (!documentVersionId)
|
|
246
|
+
throw new Error('missing_required_document_version_id');
|
|
247
|
+
const pageNumberRaw = payload.pageNumber;
|
|
248
|
+
const pageNumber = normalizePositiveInt(pageNumberRaw);
|
|
249
|
+
if (pageNumberRaw !== undefined && pageNumber === undefined) {
|
|
250
|
+
throw new Error('invalid_page_number');
|
|
251
|
+
}
|
|
252
|
+
const inputPayload = {
|
|
253
|
+
documentVersionId,
|
|
254
|
+
...pickLocaleOptions(payload),
|
|
255
|
+
};
|
|
256
|
+
const sectionId = normalizeNonEmpty(payload.sectionId);
|
|
257
|
+
if (sectionId)
|
|
258
|
+
inputPayload.sectionId = sectionId;
|
|
259
|
+
const pageVersionId = normalizeNonEmpty(payload.pageVersionId);
|
|
260
|
+
if (pageVersionId)
|
|
261
|
+
inputPayload.pageVersionId = pageVersionId;
|
|
262
|
+
if (pageNumber !== undefined)
|
|
263
|
+
inputPayload.pageNumber = pageNumber;
|
|
264
|
+
const services = await getServices();
|
|
265
|
+
const service = services.documentService;
|
|
266
|
+
if (!service || typeof service.fetchComposedFragment !== 'function') {
|
|
267
|
+
throw new Error('docman_method_missing: documentService.fetchComposedFragment');
|
|
268
|
+
}
|
|
269
|
+
return Effect.runPromise(service.fetchComposedFragment(inputPayload));
|
|
270
|
+
}
|
|
271
|
+
const parsed = parseToolId(toolId);
|
|
272
|
+
if (!parsed) {
|
|
273
|
+
throw new Error(`unknown_docman_tool: ${toolId}`);
|
|
274
|
+
}
|
|
275
|
+
const entity = parsed.entity;
|
|
276
|
+
const services = await getServices();
|
|
277
|
+
const serviceKey = buildServiceKey(entity);
|
|
278
|
+
const service = services[serviceKey];
|
|
279
|
+
if (!service) {
|
|
280
|
+
throw new Error(`docman_service_not_found: ${serviceKey}`);
|
|
281
|
+
}
|
|
282
|
+
const data = payload.data;
|
|
283
|
+
const patch = payload.patch;
|
|
284
|
+
const filter = (payload.filter ?? {});
|
|
285
|
+
const options = payload.options;
|
|
286
|
+
if (parsed.op === 'list') {
|
|
287
|
+
const listMethod = buildListMethod(entity);
|
|
288
|
+
const fn = service[listMethod];
|
|
289
|
+
if (typeof fn !== 'function')
|
|
290
|
+
throw new Error(`docman_list_method_missing: ${listMethod}`);
|
|
291
|
+
return Effect.runPromise(fn.call(service, filter, options));
|
|
292
|
+
}
|
|
293
|
+
if (parsed.op === 'get') {
|
|
294
|
+
if (!id)
|
|
295
|
+
throw new Error('missing_required_id');
|
|
296
|
+
return Effect.runPromise(service.getById(id, options));
|
|
297
|
+
}
|
|
298
|
+
if (parsed.op === 'create') {
|
|
299
|
+
if (!data || typeof data !== 'object')
|
|
300
|
+
throw new Error('missing_required_data');
|
|
301
|
+
return Effect.runPromise(service.create(data));
|
|
302
|
+
}
|
|
303
|
+
if (parsed.op === 'update') {
|
|
304
|
+
if (!id)
|
|
305
|
+
throw new Error('missing_required_id');
|
|
306
|
+
if (!patch || typeof patch !== 'object')
|
|
307
|
+
throw new Error('missing_required_patch');
|
|
308
|
+
const updateMethod = buildUpdateMethod(entity);
|
|
309
|
+
const fn = service[updateMethod];
|
|
310
|
+
if (typeof fn !== 'function')
|
|
311
|
+
throw new Error(`docman_update_method_missing: ${updateMethod}`);
|
|
312
|
+
return Effect.runPromise(fn.call(service, id, patch));
|
|
313
|
+
}
|
|
314
|
+
if (parsed.op === 'delete') {
|
|
315
|
+
if (!id)
|
|
316
|
+
throw new Error('missing_required_id');
|
|
317
|
+
const removeMethod = buildRemoveMethod(entity);
|
|
318
|
+
const fn = service[removeMethod];
|
|
319
|
+
if (typeof fn !== 'function')
|
|
320
|
+
throw new Error(`docman_remove_method_missing: ${removeMethod}`);
|
|
321
|
+
return Effect.runPromise(fn.call(service, id));
|
|
322
|
+
}
|
|
323
|
+
throw new Error(`unsupported_docman_tool: ${toolId}`);
|
|
324
|
+
}
|
package/dist/specs.d.ts
ADDED
package/dist/specs.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
const optionId = () => ({
|
|
2
|
+
name: 'id',
|
|
3
|
+
flag: '--id',
|
|
4
|
+
valueHint: '<id>',
|
|
5
|
+
description: 'Entity id',
|
|
6
|
+
type: 'string',
|
|
7
|
+
required: true,
|
|
8
|
+
});
|
|
9
|
+
const optionFilter = () => ({
|
|
10
|
+
name: 'filter',
|
|
11
|
+
flag: '--filter',
|
|
12
|
+
valueHint: '<json>',
|
|
13
|
+
description: 'Filter object (matches fields)',
|
|
14
|
+
type: 'json',
|
|
15
|
+
});
|
|
16
|
+
const optionOptions = () => ({
|
|
17
|
+
name: 'options',
|
|
18
|
+
flag: '--options',
|
|
19
|
+
valueHint: '<json>',
|
|
20
|
+
description: 'Query options (limit/offset/sort).',
|
|
21
|
+
type: 'json',
|
|
22
|
+
});
|
|
23
|
+
const optionDocumentListOptions = () => ({
|
|
24
|
+
name: 'options',
|
|
25
|
+
flag: '--options',
|
|
26
|
+
valueHint: '<json>',
|
|
27
|
+
description: 'Query options (limit/offset/sort). For document list use {"includeVersionInfo": true} to include documentVersions.',
|
|
28
|
+
type: 'json',
|
|
29
|
+
});
|
|
30
|
+
const optionData = () => ({
|
|
31
|
+
name: 'data',
|
|
32
|
+
flag: '--data',
|
|
33
|
+
valueHint: '<json>',
|
|
34
|
+
description: 'Insert payload',
|
|
35
|
+
type: 'json',
|
|
36
|
+
required: true,
|
|
37
|
+
});
|
|
38
|
+
const optionPatch = () => ({
|
|
39
|
+
name: 'patch',
|
|
40
|
+
flag: '--patch',
|
|
41
|
+
valueHint: '<json>',
|
|
42
|
+
description: 'Patch payload',
|
|
43
|
+
type: 'json',
|
|
44
|
+
required: true,
|
|
45
|
+
});
|
|
46
|
+
const optionSectionId = () => ({
|
|
47
|
+
name: 'sectionId',
|
|
48
|
+
flag: '--section-id',
|
|
49
|
+
valueHint: '<uuid>',
|
|
50
|
+
description: 'Section id',
|
|
51
|
+
type: 'string',
|
|
52
|
+
required: true,
|
|
53
|
+
});
|
|
54
|
+
const optionSectionIdOptional = () => ({
|
|
55
|
+
name: 'sectionId',
|
|
56
|
+
flag: '--section-id',
|
|
57
|
+
valueHint: '<uuid>',
|
|
58
|
+
description: 'Section id',
|
|
59
|
+
type: 'string',
|
|
60
|
+
});
|
|
61
|
+
const optionPageVersionId = () => ({
|
|
62
|
+
name: 'pageVersionId',
|
|
63
|
+
flag: '--page-version-id',
|
|
64
|
+
valueHint: '<uuid>',
|
|
65
|
+
description: 'Page version id',
|
|
66
|
+
type: 'string',
|
|
67
|
+
});
|
|
68
|
+
const optionDocumentVersionId = () => ({
|
|
69
|
+
name: 'documentVersionId',
|
|
70
|
+
flag: '--document-version-id',
|
|
71
|
+
valueHint: '<uuid>',
|
|
72
|
+
description: 'Document version id',
|
|
73
|
+
type: 'string',
|
|
74
|
+
required: true,
|
|
75
|
+
});
|
|
76
|
+
const optionParsedGraph = () => ({
|
|
77
|
+
name: 'parsedGraph',
|
|
78
|
+
flag: '--parsed-graph',
|
|
79
|
+
valueHint: '<json>',
|
|
80
|
+
description: 'Parsed heading graph JSON payload.',
|
|
81
|
+
type: 'json',
|
|
82
|
+
required: true,
|
|
83
|
+
});
|
|
84
|
+
const optionImportOptions = () => ({
|
|
85
|
+
name: 'options',
|
|
86
|
+
flag: '--options',
|
|
87
|
+
valueHint: '<json>',
|
|
88
|
+
description: 'Heading import options.',
|
|
89
|
+
type: 'json',
|
|
90
|
+
});
|
|
91
|
+
const optionPageNumber = () => ({
|
|
92
|
+
name: 'pageNumber',
|
|
93
|
+
flag: '--page-number',
|
|
94
|
+
valueHint: '<number>',
|
|
95
|
+
description: 'Composed page number (1-based).',
|
|
96
|
+
type: 'number',
|
|
97
|
+
});
|
|
98
|
+
const optionLocale = () => ({
|
|
99
|
+
name: 'locale',
|
|
100
|
+
flag: '--locale',
|
|
101
|
+
valueHint: '<lang>',
|
|
102
|
+
description: 'Locale hint (example: tr, en, tr-TR).',
|
|
103
|
+
type: 'string',
|
|
104
|
+
});
|
|
105
|
+
const optionFallbackLocale = () => ({
|
|
106
|
+
name: 'fallbackLocale',
|
|
107
|
+
flag: '--fallback-locale',
|
|
108
|
+
valueHint: '<lang>',
|
|
109
|
+
description: 'Fallback locale hint.',
|
|
110
|
+
type: 'string',
|
|
111
|
+
});
|
|
112
|
+
const optionQuery = () => ({
|
|
113
|
+
name: 'q',
|
|
114
|
+
flag: '--q',
|
|
115
|
+
valueHint: '<text>',
|
|
116
|
+
description: 'Search query text.',
|
|
117
|
+
type: 'string',
|
|
118
|
+
required: true,
|
|
119
|
+
});
|
|
120
|
+
const optionLimit = () => ({
|
|
121
|
+
name: 'limit',
|
|
122
|
+
flag: '--limit',
|
|
123
|
+
valueHint: '<number>',
|
|
124
|
+
description: 'Maximum number of hits to return.',
|
|
125
|
+
type: 'number',
|
|
126
|
+
});
|
|
127
|
+
const optionRetrievalStrategy = () => ({
|
|
128
|
+
name: 'retrievalStrategy',
|
|
129
|
+
flag: '--retrieval-strategy',
|
|
130
|
+
valueHint: '<lexical|hybrid|semantic>',
|
|
131
|
+
description: 'Retrieval mode. Defaults to lexical when omitted.',
|
|
132
|
+
type: 'string',
|
|
133
|
+
});
|
|
134
|
+
const optionConfirmName = () => ({
|
|
135
|
+
name: 'confirmName',
|
|
136
|
+
flag: '--confirm-name',
|
|
137
|
+
valueHint: '<name>',
|
|
138
|
+
description: 'Type the exact document title to confirm deletion.',
|
|
139
|
+
type: 'string',
|
|
140
|
+
required: true,
|
|
141
|
+
});
|
|
142
|
+
const ENTITIES = [
|
|
143
|
+
{ id: 'document', title: 'Document', description: 'Document record.' },
|
|
144
|
+
{ id: 'document-group', title: 'Document group', description: 'Hierarchical grouping for documents.' },
|
|
145
|
+
{ id: 'document-version', title: 'Document version', description: 'Version metadata for a document.' },
|
|
146
|
+
{ id: 'section', title: 'Section', description: 'Section record.' },
|
|
147
|
+
{ id: 'page', title: 'Page', description: 'Page record.' },
|
|
148
|
+
{ id: 'page-version', title: 'Page version', description: 'Version metadata for a page.' },
|
|
149
|
+
{ id: 'document-section-link', title: 'Document section link', description: 'Link between document version and section.' },
|
|
150
|
+
{ id: 'section-page-link', title: 'Section page link', description: 'Link between section and page version.' },
|
|
151
|
+
{ id: 'snippet', title: 'Snippet', description: 'Snippet record.' },
|
|
152
|
+
{ id: 'page-snippet-link', title: 'Page snippet link', description: 'Link between page version and snippet.' },
|
|
153
|
+
{ id: 'embed', title: 'Embed', description: 'Embed record.' },
|
|
154
|
+
{ id: 'page-embed-link', title: 'Page embed link', description: 'Link between page version and embed.' },
|
|
155
|
+
];
|
|
156
|
+
const CRUD_OPS = [
|
|
157
|
+
{
|
|
158
|
+
op: 'list',
|
|
159
|
+
title: 'List',
|
|
160
|
+
description: 'List items by filter.',
|
|
161
|
+
result: 'list',
|
|
162
|
+
options: () => [optionFilter(), optionOptions()],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
op: 'get',
|
|
166
|
+
title: 'Get',
|
|
167
|
+
description: 'Get item by id.',
|
|
168
|
+
result: 'action',
|
|
169
|
+
options: () => [optionId()],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
op: 'create',
|
|
173
|
+
title: 'Create',
|
|
174
|
+
description: 'Create item.',
|
|
175
|
+
result: 'action',
|
|
176
|
+
options: () => [optionData()],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
op: 'update',
|
|
180
|
+
title: 'Update',
|
|
181
|
+
description: 'Update item by id.',
|
|
182
|
+
result: 'action',
|
|
183
|
+
options: () => [optionId(), optionPatch()],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
op: 'delete',
|
|
187
|
+
title: 'Delete',
|
|
188
|
+
description: 'Delete item by id.',
|
|
189
|
+
result: 'action',
|
|
190
|
+
options: () => [optionId()],
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
function buildSpecs(entity) {
|
|
194
|
+
const segments = entity.segments ?? entity.id.split('-');
|
|
195
|
+
return CRUD_OPS.map((op) => ({
|
|
196
|
+
id: `docman-${entity.id}-${op.op}`,
|
|
197
|
+
group: 'docman',
|
|
198
|
+
title: `${op.title} ${entity.title}`,
|
|
199
|
+
description: `${op.description} ${entity.description}`,
|
|
200
|
+
command: ['docman', ...segments, op.op],
|
|
201
|
+
result: op.result,
|
|
202
|
+
options: entity.id === 'document' && op.op === 'list' ? [optionFilter(), optionDocumentListOptions()] : op.options(),
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
const SAFE_DELETE_SPECS = [
|
|
206
|
+
{
|
|
207
|
+
id: 'docman-document-delete-safe',
|
|
208
|
+
group: 'docman',
|
|
209
|
+
title: 'Delete Document Safely',
|
|
210
|
+
description: 'Delete a document with its versions and orphan-only section/page graph.',
|
|
211
|
+
command: ['docman', 'document', 'delete-safe'],
|
|
212
|
+
result: 'action',
|
|
213
|
+
options: [optionId(), optionConfirmName()],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
id: 'docman-document-version-delete-safe',
|
|
217
|
+
group: 'docman',
|
|
218
|
+
title: 'Delete Document version Safely',
|
|
219
|
+
description: 'Delete a document version and orphan-only section/page graph.',
|
|
220
|
+
command: ['docman', 'document', 'version', 'delete-safe'],
|
|
221
|
+
result: 'action',
|
|
222
|
+
options: [optionId()],
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
id: 'docman-document-version-import-headings',
|
|
226
|
+
group: 'docman',
|
|
227
|
+
title: 'Import Document version Headings',
|
|
228
|
+
description: 'Import a parsed heading graph into one document version.',
|
|
229
|
+
command: ['docman', 'document', 'version', 'import-headings'],
|
|
230
|
+
result: 'action',
|
|
231
|
+
options: [optionDocumentVersionId(), optionParsedGraph(), optionImportOptions()],
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
const CUSTOM_SPECS = [
|
|
235
|
+
{
|
|
236
|
+
id: 'docman-document-section-link-usage-list',
|
|
237
|
+
group: 'docman',
|
|
238
|
+
title: 'List Section usage',
|
|
239
|
+
description: 'List document versions linked to a section.',
|
|
240
|
+
command: ['docman', 'document', 'section', 'usage', 'list'],
|
|
241
|
+
result: 'list',
|
|
242
|
+
options: [optionSectionId()],
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: 'docman-document-compose-index',
|
|
246
|
+
group: 'docman',
|
|
247
|
+
title: 'Build Document Compose Index',
|
|
248
|
+
description: 'Build index with sections/pages and dynamic composed pages.',
|
|
249
|
+
command: ['docman', 'document', 'compose', 'index'],
|
|
250
|
+
result: 'action',
|
|
251
|
+
options: [optionDocumentVersionId(), optionLocale(), optionFallbackLocale()],
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: 'docman-document-compose-fetch',
|
|
255
|
+
group: 'docman',
|
|
256
|
+
title: 'Fetch Composed Fragment',
|
|
257
|
+
description: 'Fetch composed source fragment with resolved asset references (document, section, or page).',
|
|
258
|
+
command: ['docman', 'document', 'compose', 'fetch'],
|
|
259
|
+
result: 'action',
|
|
260
|
+
options: [
|
|
261
|
+
optionDocumentVersionId(),
|
|
262
|
+
optionSectionIdOptional(),
|
|
263
|
+
optionPageVersionId(),
|
|
264
|
+
optionPageNumber(),
|
|
265
|
+
optionLocale(),
|
|
266
|
+
optionFallbackLocale(),
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: 'docman-document-index-build',
|
|
271
|
+
group: 'docman',
|
|
272
|
+
title: 'Build Persisted Document Index',
|
|
273
|
+
description: 'Build persisted retrieval index rows for one document version.',
|
|
274
|
+
command: ['docman', 'document', 'index', 'build'],
|
|
275
|
+
result: 'action',
|
|
276
|
+
options: [optionDocumentVersionId(), optionLocale(), optionFallbackLocale()],
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: 'docman-document-index-get',
|
|
280
|
+
group: 'docman',
|
|
281
|
+
title: 'Get Persisted Document Index',
|
|
282
|
+
description: 'Read persisted retrieval index rows for one document version.',
|
|
283
|
+
command: ['docman', 'document', 'index', 'get'],
|
|
284
|
+
result: 'action',
|
|
285
|
+
options: [optionDocumentVersionId(), optionLocale(), optionFallbackLocale()],
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: 'docman-document-summary-build',
|
|
289
|
+
group: 'docman',
|
|
290
|
+
title: 'Build Persisted Document Summaries',
|
|
291
|
+
description: 'Build persisted document, section, and page summaries for one document version.',
|
|
292
|
+
command: ['docman', 'document', 'summary', 'build'],
|
|
293
|
+
result: 'action',
|
|
294
|
+
options: [optionDocumentVersionId(), optionLocale(), optionFallbackLocale()],
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: 'docman-document-summary-get',
|
|
298
|
+
group: 'docman',
|
|
299
|
+
title: 'Get Persisted Document Summaries',
|
|
300
|
+
description: 'Read persisted document, section, and page summaries for one document version.',
|
|
301
|
+
command: ['docman', 'document', 'summary', 'get'],
|
|
302
|
+
result: 'action',
|
|
303
|
+
options: [optionDocumentVersionId(), optionLocale(), optionFallbackLocale()],
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: 'docman-document-search',
|
|
307
|
+
group: 'docman',
|
|
308
|
+
title: 'Search Document Index',
|
|
309
|
+
description: 'Search persisted retrieval index rows for one document version.',
|
|
310
|
+
command: ['docman', 'document', 'search'],
|
|
311
|
+
result: 'action',
|
|
312
|
+
options: [
|
|
313
|
+
optionDocumentVersionId(),
|
|
314
|
+
optionQuery(),
|
|
315
|
+
optionLimit(),
|
|
316
|
+
optionRetrievalStrategy(),
|
|
317
|
+
optionLocale(),
|
|
318
|
+
optionFallbackLocale(),
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: 'docman-document-answer-pack',
|
|
323
|
+
group: 'docman',
|
|
324
|
+
title: 'Get Document Answer Pack',
|
|
325
|
+
description: 'Get answer, citations, and provenance for one document version query.',
|
|
326
|
+
command: ['docman', 'document', 'answer-pack'],
|
|
327
|
+
result: 'action',
|
|
328
|
+
options: [
|
|
329
|
+
optionDocumentVersionId(),
|
|
330
|
+
optionQuery(),
|
|
331
|
+
optionLimit(),
|
|
332
|
+
optionRetrievalStrategy(),
|
|
333
|
+
optionLocale(),
|
|
334
|
+
optionFallbackLocale(),
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
];
|
|
338
|
+
export const DOCMAN_TOOL_SPECS = [
|
|
339
|
+
...ENTITIES.flatMap((entity) => buildSpecs(entity)),
|
|
340
|
+
...SAFE_DELETE_SPECS,
|
|
341
|
+
...CUSTOM_SPECS,
|
|
342
|
+
];
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ToolingGroup } from './types.js';
|
|
2
|
+
import { DOCMAN_TOOL_SPECS } from './specs.js';
|
|
3
|
+
export type DocmanToolId = (typeof DOCMAN_TOOL_SPECS)[number]['id'];
|
|
4
|
+
export declare const DOCMAN_TOOL_IDS: DocmanToolId[];
|
|
5
|
+
export declare const DOCMAN_TOOL_GROUP: ToolingGroup;
|
|
6
|
+
export declare function buildDocmanToolId(segments: string[]): string;
|
|
7
|
+
export declare function isDocmanToolId(toolId: string): toolId is DocmanToolId;
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DOCMAN_TOOL_SPECS } from './specs.js';
|
|
2
|
+
export const DOCMAN_TOOL_IDS = DOCMAN_TOOL_SPECS.map((spec) => spec.id);
|
|
3
|
+
const DOCMAN_TOOL_ID_SET = new Set(DOCMAN_TOOL_IDS);
|
|
4
|
+
export const DOCMAN_TOOL_GROUP = {
|
|
5
|
+
id: 'docman',
|
|
6
|
+
title: 'Docman tools',
|
|
7
|
+
toolIds: [...DOCMAN_TOOL_IDS],
|
|
8
|
+
notes: [
|
|
9
|
+
'Docman tools manage documents and hierarchical groups.',
|
|
10
|
+
'Use list filters or ids to target entities.',
|
|
11
|
+
'For list documents, use --options with {"includeVersionInfo": true} to include documentVersions.',
|
|
12
|
+
'MLG fields must be JSON objects (example: {"tr":"...","en":"..."}) and are stored as jsonb in DB.',
|
|
13
|
+
'Compose tools can build index, fetch fragments, and render markdown from document versions.',
|
|
14
|
+
'Create/update payloads are sent via data/patch fields (JSON).',
|
|
15
|
+
'Document groups can be nested via parentGroupId.',
|
|
16
|
+
],
|
|
17
|
+
examples: [
|
|
18
|
+
'POST /api/agent/tools/docman-document-list/invoke {"input":{"filter":{"title":"Spec"}}}',
|
|
19
|
+
'POST /api/agent/tools/docman-document-list/invoke {"input":{"filter":{},"options":{"includeVersionInfo":true}}}',
|
|
20
|
+
'POST /api/agent/tools/docman-document-version-create/invoke {"input":{"data":{"documentId":"<documentId>","version":3,"status":"draft","releaseNotesMl":{"tr":"Surum notu","en":"Release note"}}}}',
|
|
21
|
+
'POST /api/agent/tools/docman-document-compose-index/invoke {"input":{"pathParams":{"id":"<documentVersionId>"},"body":{"options":{"locale":"tr","fallbackLocale":"en"}}}}',
|
|
22
|
+
'POST /api/agent/tools/docman-document-compose-fetch/invoke {"input":{"pathParams":{"id":"<documentVersionId>"},"body":{"pageNumber":2}}}',
|
|
23
|
+
'POST /api/agent/tools/docman-document-group-create/invoke {"input":{"data":{"title":"Application Notes"}}}',
|
|
24
|
+
'POST /api/agent/tools/docman-page-create/invoke {"input":{"data":{"pageUid":"PAG-1","title":"Introduction"}}}',
|
|
25
|
+
'POST /api/agent/tools/docman-document-update/invoke {"input":{"id":"<docId>","patch":{"groupId":"<groupId>"}}}',
|
|
26
|
+
'POST /api/agent/tools/docman-document-group-list/invoke {"input":{"filter":{"parentGroupId":"<groupId>"}}}',
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
export function buildDocmanToolId(segments) {
|
|
30
|
+
const normalized = segments.map((segment) => segment.trim()).filter(Boolean);
|
|
31
|
+
return 'docman-' + normalized.join('-').toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
export function isDocmanToolId(toolId) {
|
|
34
|
+
return DOCMAN_TOOL_ID_SET.has(toolId);
|
|
35
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ToolingOptionType = 'string' | 'number' | 'boolean' | 'json';
|
|
2
|
+
export type ToolingOptionSpec = {
|
|
3
|
+
name: string;
|
|
4
|
+
flag: string;
|
|
5
|
+
valueHint?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
type: ToolingOptionType;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ToolingResultKind = 'list' | 'action';
|
|
11
|
+
export type ToolingSpec = {
|
|
12
|
+
id: string;
|
|
13
|
+
group: string;
|
|
14
|
+
title: string;
|
|
15
|
+
description: string;
|
|
16
|
+
command: string[];
|
|
17
|
+
result: ToolingResultKind;
|
|
18
|
+
options?: ToolingOptionSpec[];
|
|
19
|
+
};
|
|
20
|
+
export type ToolingGroup = {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
toolIds: string[];
|
|
24
|
+
notes?: string[];
|
|
25
|
+
examples?: string[];
|
|
26
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aopslab/domain-ops-docman",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Docman operational utilities (seed, maintenance, offline ops).",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
"./specs": {
|
|
13
|
+
"types": "./dist/specs.d.ts",
|
|
14
|
+
"import": "./dist/specs.js",
|
|
15
|
+
"default": "./dist/specs.js"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"!**/*.tsbuildinfo",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"NOTICE"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"dotenv": "^17.3.1",
|
|
31
|
+
"effect": "3.20.0",
|
|
32
|
+
"@aopslab/domain-kit-docman": "0.1.4"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org"
|
|
37
|
+
},
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/eeemzs/docman.git",
|
|
42
|
+
"directory": "docman-ops"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -b tsconfig.lib.json"
|
|
46
|
+
}
|
|
47
|
+
}
|