@morphllm/subagents 0.1.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/README.md +146 -0
- package/dist/core/index.d.mts +68 -0
- package/dist/core/index.d.ts +68 -0
- package/dist/core/index.js +221 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +218 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/docx/index.d.mts +110 -0
- package/dist/docx/index.d.ts +110 -0
- package/dist/docx/index.js +552 -0
- package/dist/docx/index.js.map +1 -0
- package/dist/docx/index.mjs +549 -0
- package/dist/docx/index.mjs.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +554 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +549 -0
- package/dist/index.mjs.map +1 -0
- package/dist/pdf/index.d.mts +17 -0
- package/dist/pdf/index.d.ts +17 -0
- package/dist/pdf/index.js +10 -0
- package/dist/pdf/index.js.map +1 -0
- package/dist/pdf/index.mjs +7 -0
- package/dist/pdf/index.mjs.map +1 -0
- package/dist/types-BEtL6Wum.d.ts +48 -0
- package/dist/types-D9rS2MQq.d.mts +82 -0
- package/dist/types-D9rS2MQq.d.ts +82 -0
- package/dist/types-DBtV_NyH.d.mts +48 -0
- package/package.json +71 -0
- package/src/core/base-agent.ts +230 -0
- package/src/core/base-client.ts +93 -0
- package/src/core/index.ts +17 -0
- package/src/core/types.ts +64 -0
- package/src/docx/agent.ts +311 -0
- package/src/docx/client.ts +69 -0
- package/src/docx/index.ts +18 -0
- package/src/docx/types.ts +68 -0
- package/src/index.ts +66 -0
- package/src/pdf/index.ts +23 -0
- package/src/pdf/types.ts +52 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types shared across all subagents
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Tool definition for OpenAI-compatible APIs */
|
|
6
|
+
export interface Tool {
|
|
7
|
+
type: 'function';
|
|
8
|
+
function: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Chat message for conversation history */
|
|
16
|
+
export interface ChatMessage {
|
|
17
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
18
|
+
content: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
tool_call_id?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Tool call tracking */
|
|
24
|
+
export interface ToolCall {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
arguments: Record<string, unknown>;
|
|
28
|
+
result?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
status: 'pending' | 'running' | 'completed' | 'error';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Stream events for real-time UI updates */
|
|
34
|
+
export type StreamEvent =
|
|
35
|
+
| { type: 'message_start'; message: { role: 'assistant' } }
|
|
36
|
+
| { type: 'content_delta'; delta: { text: string } }
|
|
37
|
+
| { type: 'tool_start'; tool: { id: string; name: string; arguments: Record<string, unknown> } }
|
|
38
|
+
| { type: 'tool_end'; tool: { id: string; result?: string; error?: string } }
|
|
39
|
+
| { type: 'message_end' }
|
|
40
|
+
| { type: 'error'; error: string };
|
|
41
|
+
|
|
42
|
+
/** Agent run result */
|
|
43
|
+
export interface AgentRunResult {
|
|
44
|
+
response: string;
|
|
45
|
+
toolCalls: ToolCall[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Base client options */
|
|
49
|
+
export interface BaseClientOptions {
|
|
50
|
+
/** API base URL */
|
|
51
|
+
apiUrl?: string;
|
|
52
|
+
/** Request timeout in milliseconds */
|
|
53
|
+
timeout?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Base agent options */
|
|
57
|
+
export interface BaseAgentOptions extends BaseClientOptions {
|
|
58
|
+
/** OpenAI-compatible client instance */
|
|
59
|
+
openai?: any;
|
|
60
|
+
/** Model to use */
|
|
61
|
+
model?: string;
|
|
62
|
+
/** System instructions */
|
|
63
|
+
instructions?: string;
|
|
64
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DocxAgent - AI agent for DOCX document editing
|
|
3
|
+
*
|
|
4
|
+
* Uses OpenAI-compatible API to process requests and execute
|
|
5
|
+
* document editing operations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { BaseAgent } from '../core/base-agent';
|
|
9
|
+
import type { Tool } from '../core/types';
|
|
10
|
+
import { DocxClient } from './client';
|
|
11
|
+
import type { DocxAgentOptions } from './types';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_INSTRUCTIONS = `You are an expert DOCX document editing assistant.
|
|
14
|
+
|
|
15
|
+
When editing documents:
|
|
16
|
+
1. First read the document to understand its structure
|
|
17
|
+
2. Use track changes for all modifications
|
|
18
|
+
3. Add comments to flag issues or request clarification
|
|
19
|
+
4. Be precise with paragraph text matching - use unique text snippets
|
|
20
|
+
|
|
21
|
+
Available tools:
|
|
22
|
+
- read_document: Read the document content
|
|
23
|
+
- add_comment: Add a comment to a specific paragraph
|
|
24
|
+
- insert_text: Insert text within a paragraph (tracked change)
|
|
25
|
+
- propose_deletion: Mark text for deletion (tracked change)
|
|
26
|
+
- reply_comment: Reply to an existing comment
|
|
27
|
+
- resolve_comment: Mark a comment as resolved
|
|
28
|
+
- delete_comment: Delete a comment
|
|
29
|
+
- insert_paragraph: Insert a new paragraph
|
|
30
|
+
- validate_document: Validate DOCX structure`;
|
|
31
|
+
|
|
32
|
+
const TOOLS: Tool[] = [
|
|
33
|
+
{
|
|
34
|
+
type: 'function',
|
|
35
|
+
function: {
|
|
36
|
+
name: 'read_document',
|
|
37
|
+
description: 'Read the document content as plain text',
|
|
38
|
+
parameters: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
41
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
42
|
+
},
|
|
43
|
+
required: ['doc_id'],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: {
|
|
50
|
+
name: 'add_comment',
|
|
51
|
+
description: 'Add a comment to a specific paragraph in the document',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
56
|
+
para_text: { type: 'string', description: 'Unique text from the target paragraph' },
|
|
57
|
+
comment: { type: 'string', description: 'Comment text to add' },
|
|
58
|
+
highlight: { type: 'string', description: 'Optional specific text to highlight' },
|
|
59
|
+
},
|
|
60
|
+
required: ['doc_id', 'para_text', 'comment'],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'function',
|
|
66
|
+
function: {
|
|
67
|
+
name: 'insert_text',
|
|
68
|
+
description: 'Insert text within a paragraph (creates a tracked change)',
|
|
69
|
+
parameters: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
73
|
+
para_text: { type: 'string', description: 'Unique text from the target paragraph' },
|
|
74
|
+
after: { type: 'string', description: 'Text after which to insert' },
|
|
75
|
+
new_text: { type: 'string', description: 'Text to insert' },
|
|
76
|
+
},
|
|
77
|
+
required: ['doc_id', 'para_text', 'after', 'new_text'],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'function',
|
|
83
|
+
function: {
|
|
84
|
+
name: 'propose_deletion',
|
|
85
|
+
description: 'Mark text for deletion (creates a tracked change)',
|
|
86
|
+
parameters: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
properties: {
|
|
89
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
90
|
+
para_text: { type: 'string', description: 'Unique text from the target paragraph' },
|
|
91
|
+
target: { type: 'string', description: 'Specific text to delete (optional, defaults to whole paragraph)' },
|
|
92
|
+
},
|
|
93
|
+
required: ['doc_id', 'para_text'],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: 'function',
|
|
99
|
+
function: {
|
|
100
|
+
name: 'reply_comment',
|
|
101
|
+
description: 'Reply to an existing comment',
|
|
102
|
+
parameters: {
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: {
|
|
105
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
106
|
+
comment_id: { type: 'string', description: 'ID of the comment to reply to' },
|
|
107
|
+
reply: { type: 'string', description: 'Reply text' },
|
|
108
|
+
},
|
|
109
|
+
required: ['doc_id', 'comment_id', 'reply'],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
type: 'function',
|
|
115
|
+
function: {
|
|
116
|
+
name: 'resolve_comment',
|
|
117
|
+
description: 'Mark a comment as resolved',
|
|
118
|
+
parameters: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: {
|
|
121
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
122
|
+
comment_id: { type: 'string', description: 'ID of the comment to resolve' },
|
|
123
|
+
},
|
|
124
|
+
required: ['doc_id', 'comment_id'],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'function',
|
|
130
|
+
function: {
|
|
131
|
+
name: 'delete_comment',
|
|
132
|
+
description: 'Delete a comment and its replies',
|
|
133
|
+
parameters: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
137
|
+
comment_id: { type: 'string', description: 'ID of the comment to delete' },
|
|
138
|
+
},
|
|
139
|
+
required: ['doc_id', 'comment_id'],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: 'function',
|
|
145
|
+
function: {
|
|
146
|
+
name: 'insert_paragraph',
|
|
147
|
+
description: 'Insert a new paragraph after existing text',
|
|
148
|
+
parameters: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
152
|
+
after_text: { type: 'string', description: 'Text after which to insert the new paragraph' },
|
|
153
|
+
new_text: { type: 'string', description: 'Content of the new paragraph' },
|
|
154
|
+
},
|
|
155
|
+
required: ['doc_id', 'after_text', 'new_text'],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: 'function',
|
|
161
|
+
function: {
|
|
162
|
+
name: 'validate_document',
|
|
163
|
+
description: 'Validate the document structure',
|
|
164
|
+
parameters: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
doc_id: { type: 'string', description: 'Document ID' },
|
|
168
|
+
},
|
|
169
|
+
required: ['doc_id'],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
export class DocxAgent extends BaseAgent<DocxClient> {
|
|
176
|
+
private documentId?: string;
|
|
177
|
+
|
|
178
|
+
constructor(options: DocxAgentOptions = {}) {
|
|
179
|
+
const client = new DocxClient(options);
|
|
180
|
+
super({ ...options, client });
|
|
181
|
+
this.documentId = options.documentId;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
protected getDefaultModel(): string {
|
|
185
|
+
return 'moonshot-v1-32k';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
protected getDefaultInstructions(): string {
|
|
189
|
+
return this.documentId
|
|
190
|
+
? `${DEFAULT_INSTRUCTIONS}\n\nCurrent document ID: ${this.documentId}`
|
|
191
|
+
: DEFAULT_INSTRUCTIONS;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
protected getTools(): Tool[] {
|
|
195
|
+
return TOOLS;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Set the current document ID */
|
|
199
|
+
setDocument(docId: string) {
|
|
200
|
+
this.documentId = docId;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Get current document ID */
|
|
204
|
+
getDocumentId(): string | undefined {
|
|
205
|
+
return this.documentId;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected async executeTool(name: string, args: Record<string, unknown>): Promise<string> {
|
|
209
|
+
const docId = (args.doc_id as string) || this.documentId;
|
|
210
|
+
|
|
211
|
+
if (!docId) {
|
|
212
|
+
return 'Error: No document ID provided. Please upload a document first.';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
switch (name) {
|
|
217
|
+
case 'read_document': {
|
|
218
|
+
const result = await this.client.read(docId);
|
|
219
|
+
return `Document content (${result.paragraphs} paragraphs):\n\n${result.content}`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
case 'add_comment': {
|
|
223
|
+
const result = await this.client.edit(docId, [
|
|
224
|
+
{
|
|
225
|
+
type: 'add_comment',
|
|
226
|
+
para_text: args.para_text as string,
|
|
227
|
+
comment: args.comment as string,
|
|
228
|
+
highlight: args.highlight as string | undefined,
|
|
229
|
+
},
|
|
230
|
+
]);
|
|
231
|
+
return result.results[0];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
case 'insert_text': {
|
|
235
|
+
const result = await this.client.edit(docId, [
|
|
236
|
+
{
|
|
237
|
+
type: 'insert_text',
|
|
238
|
+
para_text: args.para_text as string,
|
|
239
|
+
after: args.after as string,
|
|
240
|
+
new_text: args.new_text as string,
|
|
241
|
+
},
|
|
242
|
+
]);
|
|
243
|
+
return result.results[0];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
case 'propose_deletion': {
|
|
247
|
+
const result = await this.client.edit(docId, [
|
|
248
|
+
{
|
|
249
|
+
type: 'propose_deletion',
|
|
250
|
+
para_text: args.para_text as string,
|
|
251
|
+
target: args.target as string | undefined,
|
|
252
|
+
},
|
|
253
|
+
]);
|
|
254
|
+
return result.results[0];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case 'reply_comment': {
|
|
258
|
+
const result = await this.client.edit(docId, [
|
|
259
|
+
{
|
|
260
|
+
type: 'reply_comment',
|
|
261
|
+
comment_id: args.comment_id as string,
|
|
262
|
+
reply: args.reply as string,
|
|
263
|
+
},
|
|
264
|
+
]);
|
|
265
|
+
return result.results[0];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
case 'resolve_comment': {
|
|
269
|
+
const result = await this.client.edit(docId, [
|
|
270
|
+
{
|
|
271
|
+
type: 'resolve_comment',
|
|
272
|
+
comment_id: args.comment_id as string,
|
|
273
|
+
},
|
|
274
|
+
]);
|
|
275
|
+
return result.results[0];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
case 'delete_comment': {
|
|
279
|
+
const result = await this.client.edit(docId, [
|
|
280
|
+
{
|
|
281
|
+
type: 'delete_comment',
|
|
282
|
+
comment_id: args.comment_id as string,
|
|
283
|
+
},
|
|
284
|
+
]);
|
|
285
|
+
return result.results[0];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
case 'insert_paragraph': {
|
|
289
|
+
const result = await this.client.edit(docId, [
|
|
290
|
+
{
|
|
291
|
+
type: 'insert_paragraph',
|
|
292
|
+
after_text: args.after_text as string,
|
|
293
|
+
new_text: args.new_text as string,
|
|
294
|
+
},
|
|
295
|
+
]);
|
|
296
|
+
return result.results[0];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
case 'validate_document': {
|
|
300
|
+
const result = await this.client.validate(docId);
|
|
301
|
+
return `${result.result}: ${result.output}`;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
default:
|
|
305
|
+
return `Error: Unknown tool '${name}'`;
|
|
306
|
+
}
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return `Error: ${error instanceof Error ? error.message : String(error)}`;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DocxClient - HTTP client for DOCX document API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { BaseClient } from '../core/base-client';
|
|
6
|
+
import type {
|
|
7
|
+
DocxClientOptions,
|
|
8
|
+
DocumentInfo,
|
|
9
|
+
ReadResponse,
|
|
10
|
+
EditOperation,
|
|
11
|
+
EditResponse,
|
|
12
|
+
ValidateResponse,
|
|
13
|
+
} from './types';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_API_URL = 'https://docx-api-service-production.up.railway.app';
|
|
16
|
+
|
|
17
|
+
export class DocxClient extends BaseClient {
|
|
18
|
+
constructor(options: DocxClientOptions = {}) {
|
|
19
|
+
super(options);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected getDefaultApiUrl(): string {
|
|
23
|
+
return process.env.DOCX_API_URL || DEFAULT_API_URL;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Upload a DOCX document.
|
|
28
|
+
*/
|
|
29
|
+
async upload(file: File | Blob, filename?: string): Promise<DocumentInfo> {
|
|
30
|
+
const formData = new FormData();
|
|
31
|
+
formData.append('file', file, filename || 'document.docx');
|
|
32
|
+
return this.postFormData('/documents/upload', formData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Download a DOCX document.
|
|
37
|
+
*/
|
|
38
|
+
async download(docId: string): Promise<Blob> {
|
|
39
|
+
return this.downloadBlob(`/documents/${docId}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Read document content as plain text.
|
|
44
|
+
*/
|
|
45
|
+
async read(docId: string): Promise<ReadResponse> {
|
|
46
|
+
return this.post(`/documents/${docId}/read`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Execute edit operations on a document.
|
|
51
|
+
*/
|
|
52
|
+
async edit(docId: string, operations: EditOperation[]): Promise<EditResponse> {
|
|
53
|
+
return this.post(`/documents/${docId}/edit`, { operations });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Validate document structure.
|
|
58
|
+
*/
|
|
59
|
+
async validate(docId: string): Promise<ValidateResponse> {
|
|
60
|
+
return this.post(`/documents/${docId}/validate`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Delete a document from storage.
|
|
65
|
+
*/
|
|
66
|
+
async deleteDocument(docId: string): Promise<void> {
|
|
67
|
+
return this.delete(`/documents/${docId}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @morphllm/subagents/docx
|
|
3
|
+
*
|
|
4
|
+
* DOCX document editing subagent for track changes, comments, and more.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { DocxClient } from './client';
|
|
8
|
+
export { DocxAgent } from './agent';
|
|
9
|
+
export type {
|
|
10
|
+
DocumentInfo,
|
|
11
|
+
ReadResponse,
|
|
12
|
+
EditOperation,
|
|
13
|
+
EditOperationType,
|
|
14
|
+
EditResponse,
|
|
15
|
+
ValidateResponse,
|
|
16
|
+
DocxClientOptions,
|
|
17
|
+
DocxAgentOptions,
|
|
18
|
+
} from './types';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for DOCX subagent
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { BaseClientOptions, BaseAgentOptions } from '../core/types';
|
|
6
|
+
|
|
7
|
+
/** Document info returned after upload */
|
|
8
|
+
export interface DocumentInfo {
|
|
9
|
+
doc_id: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Response from reading document content */
|
|
14
|
+
export interface ReadResponse {
|
|
15
|
+
content: string;
|
|
16
|
+
paragraphs: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Edit operation types */
|
|
20
|
+
export type EditOperationType =
|
|
21
|
+
| 'add_comment'
|
|
22
|
+
| 'reply_comment'
|
|
23
|
+
| 'resolve_comment'
|
|
24
|
+
| 'delete_comment'
|
|
25
|
+
| 'insert_text'
|
|
26
|
+
| 'insert_paragraph'
|
|
27
|
+
| 'propose_deletion';
|
|
28
|
+
|
|
29
|
+
/** Edit operation payload */
|
|
30
|
+
export interface EditOperation {
|
|
31
|
+
type: EditOperationType;
|
|
32
|
+
para_text?: string;
|
|
33
|
+
comment?: string;
|
|
34
|
+
highlight?: string;
|
|
35
|
+
context?: string;
|
|
36
|
+
after?: string;
|
|
37
|
+
after_text?: string;
|
|
38
|
+
new_text?: string;
|
|
39
|
+
target?: string;
|
|
40
|
+
comment_id?: string;
|
|
41
|
+
reply?: string;
|
|
42
|
+
author?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Response from edit operations */
|
|
46
|
+
export interface EditResponse {
|
|
47
|
+
results: string[];
|
|
48
|
+
doc_id: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Response from document validation */
|
|
52
|
+
export interface ValidateResponse {
|
|
53
|
+
result: string;
|
|
54
|
+
valid: boolean;
|
|
55
|
+
output: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** DOCX client options */
|
|
59
|
+
export interface DocxClientOptions extends BaseClientOptions {
|
|
60
|
+
/** API URL. Defaults to Railway deployment */
|
|
61
|
+
apiUrl?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** DOCX agent options */
|
|
65
|
+
export interface DocxAgentOptions extends BaseAgentOptions {
|
|
66
|
+
/** Current document ID */
|
|
67
|
+
documentId?: string;
|
|
68
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @morphllm/subagents
|
|
3
|
+
*
|
|
4
|
+
* Modular AI subagents for document processing.
|
|
5
|
+
*
|
|
6
|
+
* Available subagents:
|
|
7
|
+
* - DOCX: Document editing with track changes and comments
|
|
8
|
+
* - PDF: Form filling (coming soon)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Import specific subagent
|
|
13
|
+
* import { DocxClient, DocxAgent } from '@morphllm/subagents/docx';
|
|
14
|
+
*
|
|
15
|
+
* // Or import everything
|
|
16
|
+
* import { DocxClient, DocxAgent } from '@morphllm/subagents';
|
|
17
|
+
*
|
|
18
|
+
* // Use the client directly
|
|
19
|
+
* const client = new DocxClient();
|
|
20
|
+
* const doc = await client.upload(file);
|
|
21
|
+
* const content = await client.read(doc.doc_id);
|
|
22
|
+
*
|
|
23
|
+
* // Or use the AI agent
|
|
24
|
+
* const agent = new DocxAgent({
|
|
25
|
+
* openai: new OpenAI({ apiKey: 'your-key' }),
|
|
26
|
+
* documentId: doc.doc_id,
|
|
27
|
+
* });
|
|
28
|
+
* const result = await agent.run('Add a comment about the first paragraph');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// Core exports
|
|
33
|
+
export { BaseClient, BaseAgent } from './core';
|
|
34
|
+
export type {
|
|
35
|
+
Tool,
|
|
36
|
+
ChatMessage,
|
|
37
|
+
ToolCall,
|
|
38
|
+
StreamEvent,
|
|
39
|
+
AgentRunResult,
|
|
40
|
+
BaseClientOptions,
|
|
41
|
+
BaseAgentOptions,
|
|
42
|
+
} from './core';
|
|
43
|
+
|
|
44
|
+
// DOCX exports
|
|
45
|
+
export { DocxClient, DocxAgent } from './docx';
|
|
46
|
+
export type {
|
|
47
|
+
DocumentInfo,
|
|
48
|
+
ReadResponse,
|
|
49
|
+
EditOperation,
|
|
50
|
+
EditOperationType,
|
|
51
|
+
EditResponse,
|
|
52
|
+
ValidateResponse,
|
|
53
|
+
DocxClientOptions,
|
|
54
|
+
DocxAgentOptions,
|
|
55
|
+
} from './docx';
|
|
56
|
+
|
|
57
|
+
// PDF exports (types only for now)
|
|
58
|
+
export type {
|
|
59
|
+
PdfDocumentInfo,
|
|
60
|
+
FormField,
|
|
61
|
+
ReadFieldsResponse,
|
|
62
|
+
FillOperation,
|
|
63
|
+
FillResponse,
|
|
64
|
+
PdfClientOptions,
|
|
65
|
+
PdfAgentOptions,
|
|
66
|
+
} from './pdf';
|
package/src/pdf/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @morphllm/subagents/pdf
|
|
3
|
+
*
|
|
4
|
+
* PDF form filling subagent (coming soon).
|
|
5
|
+
*
|
|
6
|
+
* This module will provide:
|
|
7
|
+
* - PdfClient: HTTP client for PDF form API
|
|
8
|
+
* - PdfAgent: AI agent for filling PDF forms
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
PdfDocumentInfo,
|
|
13
|
+
FormField,
|
|
14
|
+
ReadFieldsResponse,
|
|
15
|
+
FillOperation,
|
|
16
|
+
FillResponse,
|
|
17
|
+
PdfClientOptions,
|
|
18
|
+
PdfAgentOptions,
|
|
19
|
+
} from './types';
|
|
20
|
+
|
|
21
|
+
// Placeholder exports - will be implemented when PDF service is ready
|
|
22
|
+
export const PdfClient = null;
|
|
23
|
+
export const PdfAgent = null;
|
package/src/pdf/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for PDF subagent (placeholder for future implementation)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { BaseClientOptions, BaseAgentOptions } from '../core/types';
|
|
6
|
+
|
|
7
|
+
/** PDF document info */
|
|
8
|
+
export interface PdfDocumentInfo {
|
|
9
|
+
doc_id: string;
|
|
10
|
+
page_count: number;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Form field information */
|
|
15
|
+
export interface FormField {
|
|
16
|
+
name: string;
|
|
17
|
+
type: 'text' | 'checkbox' | 'radio' | 'dropdown' | 'signature';
|
|
18
|
+
value?: string;
|
|
19
|
+
options?: string[];
|
|
20
|
+
required?: boolean;
|
|
21
|
+
page: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Response from reading PDF form fields */
|
|
25
|
+
export interface ReadFieldsResponse {
|
|
26
|
+
fields: FormField[];
|
|
27
|
+
page_count: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Fill operation for a form field */
|
|
31
|
+
export interface FillOperation {
|
|
32
|
+
field_name: string;
|
|
33
|
+
value: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Response from fill operations */
|
|
37
|
+
export interface FillResponse {
|
|
38
|
+
results: string[];
|
|
39
|
+
doc_id: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** PDF client options */
|
|
43
|
+
export interface PdfClientOptions extends BaseClientOptions {
|
|
44
|
+
/** API URL for PDF service */
|
|
45
|
+
apiUrl?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** PDF agent options */
|
|
49
|
+
export interface PdfAgentOptions extends BaseAgentOptions {
|
|
50
|
+
/** Current document ID */
|
|
51
|
+
documentId?: string;
|
|
52
|
+
}
|