@morphllm/subagents 0.1.3 → 0.1.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- # @morphllm/subagents
1
+ # subagents
2
2
 
3
3
  Modular AI subagents for document processing. Built for use with OpenAI-compatible APIs.
4
4
 
@@ -38,7 +38,7 @@ The main agent handles orchestration and planning. When it encounters a speciali
38
38
  ## Installation
39
39
 
40
40
  ```bash
41
- npm install @morphllm/subagents
41
+ npm install subagents
42
42
  ```
43
43
 
44
44
  ## Available Subagents
@@ -53,7 +53,7 @@ npm install @morphllm/subagents
53
53
  ### DOCX Client (Direct API Access)
54
54
 
55
55
  ```typescript
56
- import { DocxClient } from '@morphllm/subagents/docx';
56
+ import { DocxClient } from 'subagents/docx';
57
57
 
58
58
  const client = new DocxClient();
59
59
 
@@ -77,19 +77,15 @@ const blob = await client.download(doc.doc_id);
77
77
 
78
78
  ```typescript
79
79
  import OpenAI from 'openai';
80
- import { DocxClient, DocxAgent } from '@morphllm/subagents/docx';
80
+ import { DocxAgent } from 'subagents/docx';
81
81
 
82
- const openai = new OpenAI();
83
- const client = new DocxClient();
84
-
85
- // Upload a document first
86
- const file = new File([documentBuffer], 'contract.docx');
87
- const { doc_id } = await client.upload(file);
82
+ const openai = new OpenAI({
83
+ apiKey: process.env.OPENAI_API_KEY,
84
+ });
88
85
 
89
- // Create agent with the document
90
86
  const agent = new DocxAgent({
91
87
  openai,
92
- documentId: doc_id,
88
+ documentId: 'your-doc-id',
93
89
  });
94
90
 
95
91
  // Run with natural language
@@ -97,13 +93,7 @@ const result = await agent.run('Review this contract and flag any issues');
97
93
  console.log(result.response);
98
94
  console.log(result.toolCalls);
99
95
 
100
- // Download the edited document
101
- const editedDoc = await client.download(doc_id);
102
- ```
103
-
104
- ### Streaming Responses
105
-
106
- ```typescript
96
+ // Or stream for real-time UI
107
97
  for await (const event of agent.runStream('Add comments to unclear sections')) {
108
98
  if (event.type === 'content_delta') {
109
99
  process.stdout.write(event.delta.text);
@@ -117,11 +107,11 @@ for await (const event of agent.runStream('Add comments to unclear sections')) {
117
107
 
118
108
  ```typescript
119
109
  // Import everything
120
- import { DocxClient, DocxAgent, BaseClient } from '@morphllm/subagents';
110
+ import { DocxClient, DocxAgent, BaseClient } from 'subagents';
121
111
 
122
112
  // Import specific modules
123
- import { DocxClient, DocxAgent } from '@morphllm/subagents/docx';
124
- import { BaseClient, BaseAgent } from '@morphllm/subagents/core';
113
+ import { DocxClient, DocxAgent } from 'subagents/docx';
114
+ import { BaseClient, BaseAgent } from 'subagents/core';
125
115
  ```
126
116
 
127
117
  ## Building Custom Subagents
@@ -129,8 +119,8 @@ import { BaseClient, BaseAgent } from '@morphllm/subagents/core';
129
119
  Extend the base classes to create your own subagents:
130
120
 
131
121
  ```typescript
132
- import { BaseClient, BaseAgent } from '@morphllm/subagents/core';
133
- import type { Tool } from '@morphllm/subagents/core';
122
+ import { BaseClient, BaseAgent } from 'subagents/core';
123
+ import type { Tool } from 'subagents/core';
134
124
 
135
125
  class MyClient extends BaseClient {
136
126
  protected getDefaultApiUrl() {
@@ -165,7 +155,7 @@ class MyAgent extends BaseAgent<MyClient> {
165
155
 
166
156
  | Variable | Description | Default |
167
157
  |----------|-------------|---------|
168
- | `DOCX_API_URL` | DOCX service URL | https://docx.morphllm.com |
158
+ | `DOCX_API_URL` | DOCX service URL | Railway deployment |
169
159
 
170
160
  ## License
171
161
 
@@ -0,0 +1,30 @@
1
+ import { a as BaseClientOptions } from './types-D9rS2MQq.mjs';
2
+
3
+ /**
4
+ * BaseClient - Abstract HTTP client for subagent APIs
5
+ */
6
+
7
+ declare abstract class BaseClient {
8
+ protected apiUrl: string;
9
+ protected timeout: number;
10
+ constructor(options?: BaseClientOptions);
11
+ /** Override in subclasses to provide default API URL */
12
+ protected abstract getDefaultApiUrl(): string;
13
+ /** Make a GET request */
14
+ protected get<T>(path: string): Promise<T>;
15
+ /** Make a POST request with JSON body */
16
+ protected post<T>(path: string, body?: unknown): Promise<T>;
17
+ /** Make a POST request with FormData */
18
+ protected postFormData<T>(path: string, formData: FormData): Promise<T>;
19
+ /** Make a DELETE request */
20
+ protected delete(path: string): Promise<void>;
21
+ /** Download a file as Blob */
22
+ protected downloadBlob(path: string): Promise<Blob>;
23
+ /** Health check */
24
+ health(): Promise<{
25
+ status: string;
26
+ service: string;
27
+ }>;
28
+ }
29
+
30
+ export { BaseClient as B };
@@ -0,0 +1,30 @@
1
+ import { a as BaseClientOptions } from './types-D9rS2MQq.js';
2
+
3
+ /**
4
+ * BaseClient - Abstract HTTP client for subagent APIs
5
+ */
6
+
7
+ declare abstract class BaseClient {
8
+ protected apiUrl: string;
9
+ protected timeout: number;
10
+ constructor(options?: BaseClientOptions);
11
+ /** Override in subclasses to provide default API URL */
12
+ protected abstract getDefaultApiUrl(): string;
13
+ /** Make a GET request */
14
+ protected get<T>(path: string): Promise<T>;
15
+ /** Make a POST request with JSON body */
16
+ protected post<T>(path: string, body?: unknown): Promise<T>;
17
+ /** Make a POST request with FormData */
18
+ protected postFormData<T>(path: string, formData: FormData): Promise<T>;
19
+ /** Make a DELETE request */
20
+ protected delete(path: string): Promise<void>;
21
+ /** Download a file as Blob */
22
+ protected downloadBlob(path: string): Promise<Blob>;
23
+ /** Health check */
24
+ health(): Promise<{
25
+ status: string;
26
+ service: string;
27
+ }>;
28
+ }
29
+
30
+ export { BaseClient as B };
@@ -1,32 +1,6 @@
1
- import { a as BaseClientOptions, B as BaseAgentOptions, T as Tool, C as ChatMessage, A as AgentRunResult, S as StreamEvent } from '../types-D9rS2MQq.mjs';
2
- export { b as ToolCall } from '../types-D9rS2MQq.mjs';
3
-
4
- /**
5
- * BaseClient - Abstract HTTP client for subagent APIs
6
- */
7
-
8
- declare abstract class BaseClient {
9
- protected apiUrl: string;
10
- protected timeout: number;
11
- constructor(options?: BaseClientOptions);
12
- /** Override in subclasses to provide default API URL */
13
- protected abstract getDefaultApiUrl(): string;
14
- /** Make a GET request */
15
- protected get<T>(path: string): Promise<T>;
16
- /** Make a POST request with JSON body */
17
- protected post<T>(path: string, body?: unknown): Promise<T>;
18
- /** Make a POST request with FormData */
19
- protected postFormData<T>(path: string, formData: FormData): Promise<T>;
20
- /** Make a DELETE request */
21
- protected delete(path: string): Promise<void>;
22
- /** Download a file as Blob */
23
- protected downloadBlob(path: string): Promise<Blob>;
24
- /** Health check */
25
- health(): Promise<{
26
- status: string;
27
- service: string;
28
- }>;
29
- }
1
+ export { B as BaseClient } from '../base-client-B7fgl_Wg.mjs';
2
+ import { B as BaseAgentOptions, T as Tool, C as ChatMessage, A as AgentRunResult, S as StreamEvent } from '../types-D9rS2MQq.mjs';
3
+ export { a as BaseClientOptions, b as ToolCall } from '../types-D9rS2MQq.mjs';
30
4
 
31
5
  /**
32
6
  * BaseAgent - Abstract base class for AI subagents
@@ -65,4 +39,4 @@ declare abstract class BaseAgent<TClient> {
65
39
  runStream(userMessage: string, conversationHistory?: ChatMessage[]): AsyncGenerator<StreamEvent>;
66
40
  }
67
41
 
68
- export { AgentRunResult, BaseAgent, BaseAgentOptions, BaseClient, BaseClientOptions, ChatMessage, StreamEvent, Tool };
42
+ export { AgentRunResult, BaseAgent, BaseAgentOptions, ChatMessage, StreamEvent, Tool };
@@ -1,32 +1,6 @@
1
- import { a as BaseClientOptions, B as BaseAgentOptions, T as Tool, C as ChatMessage, A as AgentRunResult, S as StreamEvent } from '../types-D9rS2MQq.js';
2
- export { b as ToolCall } from '../types-D9rS2MQq.js';
3
-
4
- /**
5
- * BaseClient - Abstract HTTP client for subagent APIs
6
- */
7
-
8
- declare abstract class BaseClient {
9
- protected apiUrl: string;
10
- protected timeout: number;
11
- constructor(options?: BaseClientOptions);
12
- /** Override in subclasses to provide default API URL */
13
- protected abstract getDefaultApiUrl(): string;
14
- /** Make a GET request */
15
- protected get<T>(path: string): Promise<T>;
16
- /** Make a POST request with JSON body */
17
- protected post<T>(path: string, body?: unknown): Promise<T>;
18
- /** Make a POST request with FormData */
19
- protected postFormData<T>(path: string, formData: FormData): Promise<T>;
20
- /** Make a DELETE request */
21
- protected delete(path: string): Promise<void>;
22
- /** Download a file as Blob */
23
- protected downloadBlob(path: string): Promise<Blob>;
24
- /** Health check */
25
- health(): Promise<{
26
- status: string;
27
- service: string;
28
- }>;
29
- }
1
+ export { B as BaseClient } from '../base-client-C6pbtqLX.js';
2
+ import { B as BaseAgentOptions, T as Tool, C as ChatMessage, A as AgentRunResult, S as StreamEvent } from '../types-D9rS2MQq.js';
3
+ export { a as BaseClientOptions, b as ToolCall } from '../types-D9rS2MQq.js';
30
4
 
31
5
  /**
32
6
  * BaseAgent - Abstract base class for AI subagents
@@ -65,4 +39,4 @@ declare abstract class BaseAgent<TClient> {
65
39
  runStream(userMessage: string, conversationHistory?: ChatMessage[]): AsyncGenerator<StreamEvent>;
66
40
  }
67
41
 
68
- export { AgentRunResult, BaseAgent, BaseAgentOptions, BaseClient, BaseClientOptions, ChatMessage, StreamEvent, Tool };
42
+ export { AgentRunResult, BaseAgent, BaseAgentOptions, ChatMessage, StreamEvent, Tool };
@@ -1,5 +1,5 @@
1
- import { BaseClient, BaseAgent } from '../core/index.mjs';
2
- import { a as BaseClientOptions, B as BaseAgentOptions, T as Tool } from '../types-D9rS2MQq.mjs';
1
+ import { B as BaseClient } from '../base-client-B7fgl_Wg.mjs';
2
+ import { a as BaseClientOptions } from '../types-D9rS2MQq.mjs';
3
3
 
4
4
  /**
5
5
  * Types for DOCX subagent
@@ -16,7 +16,61 @@ interface ReadResponse {
16
16
  paragraphs: number;
17
17
  }
18
18
  /** Edit operation types */
19
- type EditOperationType = 'add_comment' | 'reply_comment' | 'resolve_comment' | 'delete_comment' | 'insert_text' | 'insert_paragraph' | 'propose_deletion';
19
+ type EditOperationType = 'add_comment' | 'reply_comment' | 'resolve_comment' | 'delete_comment' | 'insert_text' | 'insert_paragraph' | 'propose_deletion' | 'reject_insertion' | 'restore_deletion' | 'enable_track_changes';
20
+ /** Build operation types (for document creation) */
21
+ type BuildOperationType = 'add_heading' | 'add_paragraph' | 'add_table' | 'add_image' | 'add_list_item' | 'add_hyperlink' | 'add_page_break' | 'add_section_break' | 'add_header' | 'add_footer' | 'add_page_numbers' | 'setup_styles';
22
+ /** Build operation payload */
23
+ interface BuildOperation {
24
+ type: BuildOperationType;
25
+ text?: string;
26
+ level?: number;
27
+ style?: string;
28
+ alignment?: 'left' | 'center' | 'right' | 'justify';
29
+ bold?: boolean;
30
+ italic?: boolean;
31
+ font_size?: number;
32
+ font_name?: string;
33
+ color?: string;
34
+ space_before?: number;
35
+ space_after?: number;
36
+ headers?: string[];
37
+ rows?: string[][];
38
+ header_bg_color?: string;
39
+ image_url?: string;
40
+ image_data?: string;
41
+ width?: number;
42
+ height?: number;
43
+ list_type?: 'bullet' | 'number';
44
+ url?: string;
45
+ position?: 'header' | 'footer';
46
+ format_string?: string;
47
+ section_index?: number;
48
+ base_font?: string;
49
+ base_size?: number;
50
+ heading_font?: string;
51
+ primary_color?: string;
52
+ break_type?: 'next_page' | 'continuous' | 'even_page' | 'odd_page';
53
+ }
54
+ /** Response from create operations */
55
+ interface CreateResponse {
56
+ doc_id: string;
57
+ message: string;
58
+ }
59
+ /** Response from build operations */
60
+ interface BuildResponse {
61
+ results: string[];
62
+ doc_id: string;
63
+ }
64
+ /** Document info response */
65
+ interface DocumentInfoResponse {
66
+ paragraphs: number;
67
+ tables: number;
68
+ sections: number;
69
+ title: string;
70
+ author: string;
71
+ created: string;
72
+ modified: string;
73
+ }
20
74
  /** Edit operation payload */
21
75
  interface EditOperation {
22
76
  type: EditOperationType;
@@ -49,10 +103,76 @@ interface DocxClientOptions extends BaseClientOptions {
49
103
  apiUrl?: string;
50
104
  }
51
105
  /** DOCX agent options */
52
- interface DocxAgentOptions extends BaseAgentOptions {
106
+ interface DocxAgentOptions {
107
+ /** Base URL for the API. Defaults to api.subagents.com/v1 */
108
+ baseUrl?: string;
109
+ /** API key (optional, not required for public endpoints) */
110
+ apiKey?: string;
53
111
  /** Current document ID */
54
112
  documentId?: string;
55
113
  }
114
+ /** Chat message */
115
+ interface Message {
116
+ role: 'system' | 'user' | 'assistant' | 'tool';
117
+ content: string;
118
+ tool_call_id?: string;
119
+ tool_calls?: ToolCall[];
120
+ }
121
+ /** Tool call in a message */
122
+ interface ToolCall {
123
+ id: string;
124
+ type: 'function';
125
+ function: {
126
+ name: string;
127
+ arguments: string;
128
+ };
129
+ }
130
+ /** Chat completion response (non-streaming) */
131
+ interface ChatCompletionResponse {
132
+ id: string;
133
+ object: 'chat.completion';
134
+ created: number;
135
+ model: string;
136
+ choices: {
137
+ index: number;
138
+ message: {
139
+ role: 'assistant';
140
+ content: string | null;
141
+ tool_calls?: ToolCall[];
142
+ };
143
+ finish_reason: string;
144
+ }[];
145
+ usage?: {
146
+ prompt_tokens: number;
147
+ completion_tokens: number;
148
+ total_tokens: number;
149
+ };
150
+ }
151
+ /** Stream chunk */
152
+ interface StreamChunk {
153
+ id?: string;
154
+ object?: string;
155
+ created?: number;
156
+ model?: string;
157
+ choices?: {
158
+ index: number;
159
+ delta: {
160
+ role?: string;
161
+ content?: string;
162
+ tool_calls?: {
163
+ index: number;
164
+ id?: string;
165
+ type?: string;
166
+ function?: {
167
+ name?: string;
168
+ arguments?: string;
169
+ };
170
+ }[];
171
+ };
172
+ finish_reason?: string | null;
173
+ }[];
174
+ error?: string;
175
+ }
56
176
 
57
177
  /**
58
178
  * DocxClient - HTTP client for DOCX document API
@@ -85,26 +205,88 @@ declare class DocxClient extends BaseClient {
85
205
  * Delete a document from storage.
86
206
  */
87
207
  deleteDocument(docId: string): Promise<void>;
208
+ /**
209
+ * Create a new empty DOCX document.
210
+ */
211
+ create(title?: string): Promise<CreateResponse>;
212
+ /**
213
+ * Execute build operations on a document (add content).
214
+ */
215
+ build(docId: string, operations: BuildOperation[]): Promise<BuildResponse>;
216
+ /**
217
+ * Get document information.
218
+ */
219
+ getInfo(docId: string): Promise<DocumentInfoResponse>;
220
+ /**
221
+ * Add a heading to the document.
222
+ */
223
+ addHeading(docId: string, text: string, level?: number): Promise<BuildResponse>;
224
+ /**
225
+ * Add a paragraph to the document.
226
+ */
227
+ addParagraph(docId: string, text: string, options?: Partial<BuildOperation>): Promise<BuildResponse>;
228
+ /**
229
+ * Add a table to the document.
230
+ */
231
+ addTable(docId: string, headers: string[], rows: string[][]): Promise<BuildResponse>;
232
+ /**
233
+ * Add page numbers to the document.
234
+ */
235
+ addPageNumbers(docId: string, format?: string): Promise<BuildResponse>;
88
236
  }
89
237
 
90
238
  /**
91
239
  * DocxAgent - AI agent for DOCX document editing
92
240
  *
93
- * Uses OpenAI-compatible API to process requests and execute
94
- * document editing operations.
241
+ * OpenAI Agents SDK compatible client for morph-docx.
242
+ * Talks to api.subagents.com/v1/chat/completions with model "morph-docx".
95
243
  */
96
244
 
97
- declare class DocxAgent extends BaseAgent<DocxClient> {
245
+ declare class DocxAgent {
246
+ private baseUrl;
247
+ private apiKey;
98
248
  private documentId?;
99
249
  constructor(options?: DocxAgentOptions);
100
- protected getDefaultModel(): string;
101
- protected getDefaultInstructions(): string;
102
- protected getTools(): Tool[];
103
250
  /** Set the current document ID */
104
251
  setDocument(docId: string): void;
105
252
  /** Get current document ID */
106
253
  getDocumentId(): string | undefined;
107
- protected executeTool(name: string, args: Record<string, unknown>): Promise<string>;
254
+ /**
255
+ * Send a chat completion request (non-streaming).
256
+ * This runs the full agent loop on the server and returns the final response.
257
+ */
258
+ chat(messages: Message[]): Promise<ChatCompletionResponse>;
259
+ /**
260
+ * Send a streaming chat completion request.
261
+ * Returns an async generator that yields chunks as they arrive.
262
+ */
263
+ chatStream(messages: Message[]): AsyncGenerator<StreamChunk>;
264
+ /**
265
+ * Helper: Simple completion that returns just the content string.
266
+ */
267
+ complete(userMessage: string): Promise<string>;
268
+ /**
269
+ * Create an OpenAI-compatible client configuration.
270
+ * Use this with the OpenAI SDK or OpenAI Agents SDK.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * import OpenAI from 'openai';
275
+ * import { DocxAgent } from 'subagents/docx';
276
+ *
277
+ * const agent = new DocxAgent();
278
+ * const openai = new OpenAI(agent.getOpenAIConfig());
279
+ *
280
+ * const response = await openai.chat.completions.create({
281
+ * model: 'morph-docx',
282
+ * messages: [{ role: 'user', content: 'Hello!' }],
283
+ * });
284
+ * ```
285
+ */
286
+ getOpenAIConfig(): {
287
+ baseURL: string;
288
+ apiKey: string;
289
+ };
108
290
  }
109
291
 
110
292
  export { type DocumentInfo, DocxAgent, type DocxAgentOptions, DocxClient, type DocxClientOptions, type EditOperation, type EditOperationType, type EditResponse, type ReadResponse, type ValidateResponse };