@morphllm/subagents 0.1.3 → 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.
@@ -10,9 +10,13 @@ import type {
10
10
  EditOperation,
11
11
  EditResponse,
12
12
  ValidateResponse,
13
+ BuildOperation,
14
+ BuildResponse,
15
+ CreateResponse,
16
+ DocumentInfoResponse,
13
17
  } from './types';
14
18
 
15
- const DEFAULT_API_URL = 'https://docx-api-service-production.up.railway.app';
19
+ const DEFAULT_API_URL = 'https://subagents.morphllm.com/v1/morph-docx';
16
20
 
17
21
  export class DocxClient extends BaseClient {
18
22
  constructor(options: DocxClientOptions = {}) {
@@ -66,4 +70,57 @@ export class DocxClient extends BaseClient {
66
70
  async deleteDocument(docId: string): Promise<void> {
67
71
  return this.delete(`/documents/${docId}`);
68
72
  }
73
+
74
+ // --- Creation Operations ---
75
+
76
+ /**
77
+ * Create a new empty DOCX document.
78
+ */
79
+ async create(title?: string): Promise<CreateResponse> {
80
+ return this.post('/documents/create', { title });
81
+ }
82
+
83
+ /**
84
+ * Execute build operations on a document (add content).
85
+ */
86
+ async build(docId: string, operations: BuildOperation[]): Promise<BuildResponse> {
87
+ return this.post(`/documents/${docId}/build`, { operations });
88
+ }
89
+
90
+ /**
91
+ * Get document information.
92
+ */
93
+ async getInfo(docId: string): Promise<DocumentInfoResponse> {
94
+ return this.get(`/documents/${docId}/info`);
95
+ }
96
+
97
+ // --- Convenience Methods ---
98
+
99
+ /**
100
+ * Add a heading to the document.
101
+ */
102
+ async addHeading(docId: string, text: string, level = 1): Promise<BuildResponse> {
103
+ return this.build(docId, [{ type: 'add_heading', text, level }]);
104
+ }
105
+
106
+ /**
107
+ * Add a paragraph to the document.
108
+ */
109
+ async addParagraph(docId: string, text: string, options?: Partial<BuildOperation>): Promise<BuildResponse> {
110
+ return this.build(docId, [{ type: 'add_paragraph', text, ...options }]);
111
+ }
112
+
113
+ /**
114
+ * Add a table to the document.
115
+ */
116
+ async addTable(docId: string, headers: string[], rows: string[][]): Promise<BuildResponse> {
117
+ return this.build(docId, [{ type: 'add_table', headers, rows }]);
118
+ }
119
+
120
+ /**
121
+ * Add page numbers to the document.
122
+ */
123
+ async addPageNumbers(docId: string, format = 'Page {PAGE} of {NUMPAGES}'): Promise<BuildResponse> {
124
+ return this.build(docId, [{ type: 'add_page_numbers', format_string: format }]);
125
+ }
69
126
  }
package/src/docx/types.ts CHANGED
@@ -24,7 +24,81 @@ export type EditOperationType =
24
24
  | 'delete_comment'
25
25
  | 'insert_text'
26
26
  | 'insert_paragraph'
27
- | 'propose_deletion';
27
+ | 'propose_deletion'
28
+ | 'reject_insertion'
29
+ | 'restore_deletion'
30
+ | 'enable_track_changes';
31
+
32
+ /** Build operation types (for document creation) */
33
+ export type BuildOperationType =
34
+ | 'add_heading'
35
+ | 'add_paragraph'
36
+ | 'add_table'
37
+ | 'add_image'
38
+ | 'add_list_item'
39
+ | 'add_hyperlink'
40
+ | 'add_page_break'
41
+ | 'add_section_break'
42
+ | 'add_header'
43
+ | 'add_footer'
44
+ | 'add_page_numbers'
45
+ | 'setup_styles';
46
+
47
+ /** Build operation payload */
48
+ export interface BuildOperation {
49
+ type: BuildOperationType;
50
+ text?: string;
51
+ level?: number;
52
+ style?: string;
53
+ alignment?: 'left' | 'center' | 'right' | 'justify';
54
+ bold?: boolean;
55
+ italic?: boolean;
56
+ font_size?: number;
57
+ font_name?: string;
58
+ color?: string;
59
+ space_before?: number;
60
+ space_after?: number;
61
+ headers?: string[];
62
+ rows?: string[][];
63
+ header_bg_color?: string;
64
+ image_url?: string;
65
+ image_data?: string;
66
+ width?: number;
67
+ height?: number;
68
+ list_type?: 'bullet' | 'number';
69
+ url?: string;
70
+ position?: 'header' | 'footer';
71
+ format_string?: string;
72
+ section_index?: number;
73
+ base_font?: string;
74
+ base_size?: number;
75
+ heading_font?: string;
76
+ primary_color?: string;
77
+ break_type?: 'next_page' | 'continuous' | 'even_page' | 'odd_page';
78
+ }
79
+
80
+ /** Response from create operations */
81
+ export interface CreateResponse {
82
+ doc_id: string;
83
+ message: string;
84
+ }
85
+
86
+ /** Response from build operations */
87
+ export interface BuildResponse {
88
+ results: string[];
89
+ doc_id: string;
90
+ }
91
+
92
+ /** Document info response */
93
+ export interface DocumentInfoResponse {
94
+ paragraphs: number;
95
+ tables: number;
96
+ sections: number;
97
+ title: string;
98
+ author: string;
99
+ created: string;
100
+ modified: string;
101
+ }
28
102
 
29
103
  /** Edit operation payload */
30
104
  export interface EditOperation {
@@ -62,7 +136,77 @@ export interface DocxClientOptions extends BaseClientOptions {
62
136
  }
63
137
 
64
138
  /** DOCX agent options */
65
- export interface DocxAgentOptions extends BaseAgentOptions {
139
+ export interface DocxAgentOptions {
140
+ /** Base URL for the API. Defaults to subagents.morphllm.com/v1 */
141
+ baseUrl?: string;
142
+ /** API key (optional, not required for public endpoints) */
143
+ apiKey?: string;
66
144
  /** Current document ID */
67
145
  documentId?: string;
68
146
  }
147
+
148
+ /** Chat message */
149
+ export interface Message {
150
+ role: 'system' | 'user' | 'assistant' | 'tool';
151
+ content: string;
152
+ tool_call_id?: string;
153
+ tool_calls?: ToolCall[];
154
+ }
155
+
156
+ /** Tool call in a message */
157
+ export interface ToolCall {
158
+ id: string;
159
+ type: 'function';
160
+ function: {
161
+ name: string;
162
+ arguments: string;
163
+ };
164
+ }
165
+
166
+ /** Chat completion response (non-streaming) */
167
+ export interface ChatCompletionResponse {
168
+ id: string;
169
+ object: 'chat.completion';
170
+ created: number;
171
+ model: string;
172
+ choices: {
173
+ index: number;
174
+ message: {
175
+ role: 'assistant';
176
+ content: string | null;
177
+ tool_calls?: ToolCall[];
178
+ };
179
+ finish_reason: string;
180
+ }[];
181
+ usage?: {
182
+ prompt_tokens: number;
183
+ completion_tokens: number;
184
+ total_tokens: number;
185
+ };
186
+ }
187
+
188
+ /** Stream chunk */
189
+ export interface StreamChunk {
190
+ id?: string;
191
+ object?: string;
192
+ created?: number;
193
+ model?: string;
194
+ choices?: {
195
+ index: number;
196
+ delta: {
197
+ role?: string;
198
+ content?: string;
199
+ tool_calls?: {
200
+ index: number;
201
+ id?: string;
202
+ type?: string;
203
+ function?: {
204
+ name?: string;
205
+ arguments?: string;
206
+ };
207
+ }[];
208
+ };
209
+ finish_reason?: string | null;
210
+ }[];
211
+ error?: string;
212
+ }