@majkapp/plugin-kit 3.7.3 → 3.7.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.
@@ -0,0 +1,283 @@
1
+ # Conversations API
2
+
3
+ Access and manage MAJK conversations with filtering, searching, and message handling.
4
+
5
+ ## Quick Start
6
+
7
+ ```typescript
8
+ handler: async (input, ctx) => {
9
+ // List recent conversations
10
+ const conversations = await ctx.majk.conversations.list({
11
+ status: 'active'
12
+ });
13
+
14
+ // Get specific conversation
15
+ const conv = await ctx.majk.conversations.get('conv-123');
16
+ if (conv) {
17
+ const messages = await conv.getMessages({ limit: 10 });
18
+ return { title: conv.title, messageCount: messages.length };
19
+ }
20
+
21
+ return { conversations: conversations.length };
22
+ }
23
+ ```
24
+
25
+ ## API Reference
26
+
27
+ ### get(id)
28
+
29
+ Get a conversation by ID.
30
+
31
+ ```typescript
32
+ const conv = await ctx.majk.conversations.get('conv-123');
33
+ // Returns: ConversationHandle | null
34
+ ```
35
+
36
+ ### list(filter?)
37
+
38
+ List conversations with optional filters.
39
+
40
+ ```typescript
41
+ const conversations = await ctx.majk.conversations.list({
42
+ status?: 'active' | 'completed' | 'failed' | 'cancelled',
43
+ agentId?: string,
44
+ projectId?: string,
45
+ teamMemberId?: string,
46
+ createdAfter?: Date,
47
+ createdBefore?: Date
48
+ });
49
+ // Returns: ConversationHandle[]
50
+ ```
51
+
52
+ ### exists(id)
53
+
54
+ Check if a conversation exists.
55
+
56
+ ```typescript
57
+ const exists = await ctx.majk.conversations.exists('conv-123');
58
+ // Returns: boolean
59
+ ```
60
+
61
+ ### count(filter?)
62
+
63
+ Count conversations matching a filter.
64
+
65
+ ```typescript
66
+ const count = await ctx.majk.conversations.count({ status: 'active' });
67
+ // Returns: number
68
+ ```
69
+
70
+ ### search(query)
71
+
72
+ Search conversations by text.
73
+
74
+ ```typescript
75
+ const results = await ctx.majk.conversations.search('authentication bug');
76
+ // Returns: ConversationHandle[]
77
+ ```
78
+
79
+ ### channel()
80
+
81
+ Get the event channel for conversations.
82
+
83
+ ```typescript
84
+ const channel = ctx.majk.conversations.channel();
85
+ ```
86
+
87
+ ## ConversationHandle
88
+
89
+ Handle returned from get/list operations.
90
+
91
+ ### Properties
92
+
93
+ ```typescript
94
+ interface ConversationHandle {
95
+ readonly id: string;
96
+ readonly agentId: string;
97
+ readonly title: string;
98
+ readonly status: 'active' | 'completed' | 'failed' | 'cancelled';
99
+ readonly messageCount: number;
100
+ readonly lastMessageAt?: Date;
101
+ readonly workingDirectory?: string;
102
+ readonly projectId?: string;
103
+ readonly teamMemberId?: string;
104
+ readonly createdAt: Date;
105
+ readonly updatedAt: Date;
106
+ readonly version: number;
107
+ }
108
+ ```
109
+
110
+ ### Methods
111
+
112
+ #### refresh()
113
+
114
+ Refresh the handle with latest data.
115
+
116
+ ```typescript
117
+ await conv.refresh();
118
+ ```
119
+
120
+ #### getMessages(options?)
121
+
122
+ Get conversation messages.
123
+
124
+ ```typescript
125
+ const messages = await conv.getMessages({
126
+ limit?: number,
127
+ beforeSeq?: number,
128
+ afterSeq?: number
129
+ });
130
+ // Returns: Message[]
131
+ ```
132
+
133
+ #### send(message)
134
+
135
+ Send a message to the conversation.
136
+
137
+ ```typescript
138
+ await conv.send('Please continue with the analysis');
139
+ ```
140
+
141
+ #### getAgent()
142
+
143
+ Get the agent associated with this conversation.
144
+
145
+ ```typescript
146
+ const agent = await conv.getAgent();
147
+ ```
148
+
149
+ #### onChange(handler)
150
+
151
+ Subscribe to conversation changes.
152
+
153
+ ```typescript
154
+ const unsubscribe = conv.onChange((updated) => {
155
+ console.log('Conversation updated:', updated.title);
156
+ });
157
+
158
+ // Later
159
+ unsubscribe();
160
+ ```
161
+
162
+ #### onDelete(handler)
163
+
164
+ Subscribe to deletion events.
165
+
166
+ ```typescript
167
+ const unsubscribe = conv.onDelete(() => {
168
+ console.log('Conversation was deleted');
169
+ });
170
+ ```
171
+
172
+ #### toEntity()
173
+
174
+ Convert handle to plain entity object.
175
+
176
+ ```typescript
177
+ const entity = conv.toEntity();
178
+ // Returns: Conversation
179
+ ```
180
+
181
+ ## Message Type
182
+
183
+ ```typescript
184
+ interface Message {
185
+ id: string;
186
+ conversationId: string;
187
+ role: 'user' | 'assistant' | 'tool' | 'system';
188
+ content: string;
189
+ seq: number;
190
+ createdAt: Date;
191
+ updatedAt: Date;
192
+ version: number;
193
+ }
194
+ ```
195
+
196
+ ## Common Patterns
197
+
198
+ ### Filter Active Conversations
199
+
200
+ ```typescript
201
+ const active = await ctx.majk.conversations.list({
202
+ status: 'active',
203
+ createdAfter: new Date(Date.now() - 24 * 60 * 60 * 1000) // Last 24 hours
204
+ });
205
+
206
+ for (const conv of active) {
207
+ ctx.logger.info(`Active: ${conv.title} (${conv.messageCount} messages)`);
208
+ }
209
+ ```
210
+
211
+ ### Get Recent Messages
212
+
213
+ ```typescript
214
+ const conv = await ctx.majk.conversations.get(conversationId);
215
+ if (conv) {
216
+ // Get last 20 messages
217
+ const messages = await conv.getMessages({ limit: 20 });
218
+
219
+ // Get messages before a specific sequence
220
+ const older = await conv.getMessages({ beforeSeq: 50, limit: 10 });
221
+ }
222
+ ```
223
+
224
+ ### Search and Analyze
225
+
226
+ ```typescript
227
+ const results = await ctx.majk.conversations.search('error handling');
228
+
229
+ for (const conv of results) {
230
+ const messages = await conv.getMessages();
231
+ const errorMessages = messages.filter(m =>
232
+ m.content.toLowerCase().includes('error')
233
+ );
234
+
235
+ ctx.logger.info(`${conv.title}: ${errorMessages.length} error-related messages`);
236
+ }
237
+ ```
238
+
239
+ ### Monitor Conversation Changes
240
+
241
+ ```typescript
242
+ .onReady(async (ctx, cleanup) => {
243
+ const conversations = await ctx.majk.conversations.list({ status: 'active' });
244
+
245
+ const unsubscribes = conversations.map(conv =>
246
+ conv.onChange((updated) => {
247
+ ctx.logger.info(`Conversation ${updated.id} updated`);
248
+ })
249
+ );
250
+
251
+ cleanup(() => {
252
+ unsubscribes.forEach(unsub => unsub());
253
+ });
254
+ })
255
+ ```
256
+
257
+ ### Aggregate Statistics
258
+
259
+ ```typescript
260
+ async function getConversationStats() {
261
+ const [active, completed, failed] = await Promise.all([
262
+ ctx.majk.conversations.count({ status: 'active' }),
263
+ ctx.majk.conversations.count({ status: 'completed' }),
264
+ ctx.majk.conversations.count({ status: 'failed' })
265
+ ]);
266
+
267
+ return { active, completed, failed, total: active + completed + failed };
268
+ }
269
+ ```
270
+
271
+ ## Best Practices
272
+
273
+ 1. **Use filters** - Avoid listing all conversations when possible
274
+ 2. **Paginate messages** - Use limit/beforeSeq for large conversations
275
+ 3. **Cleanup subscriptions** - Always unsubscribe from onChange/onDelete
276
+ 4. **Refresh when needed** - Call refresh() before critical operations
277
+ 5. **Handle null** - get() may return null if conversation doesn't exist
278
+
279
+ ## Next Steps
280
+
281
+ Run `npx @majkapp/plugin-kit --context` - Full context API
282
+ Run `npx @majkapp/plugin-kit --tasks` - Task management
283
+ Run `npx @majkapp/plugin-kit --agents` - Agent configuration
@@ -0,0 +1,196 @@
1
+ # Delegation API
2
+
3
+ Multi-agent task delegation with witness-based verification. Delegate tasks to teammates and verify completion with automated checks.
4
+
5
+ ## Quick Start
6
+
7
+ ```typescript
8
+ handler: async (input, ctx) => {
9
+ // List available teammates
10
+ const { teammates } = await ctx.majk.delegation.list_teammates();
11
+
12
+ // Delegate a task
13
+ const result = await ctx.majk.delegation.delegate_task({
14
+ teammate: 'code-reviewer',
15
+ task: 'Review the auth module for security issues',
16
+ witness: { bash: 'npm test' }
17
+ });
18
+
19
+ // Wait for completion
20
+ const status = await ctx.majk.delegation.await_task({
21
+ taskId: result.taskId
22
+ });
23
+
24
+ return { success: status.status === 'completed' };
25
+ }
26
+ ```
27
+
28
+ ## API Reference
29
+
30
+ ### list_teammates()
31
+
32
+ List all available teammates that can be delegated tasks to.
33
+
34
+ ```typescript
35
+ const { teammates, count } = await ctx.majk.delegation.list_teammates();
36
+ // teammates: Array<{ id, name, skills?, description? }>
37
+ ```
38
+
39
+ ### delegate_task(input)
40
+
41
+ Delegate a task to a teammate asynchronously. Returns immediately with a task ID.
42
+
43
+ ```typescript
44
+ const result = await ctx.majk.delegation.delegate_task({
45
+ teammate: string, // Teammate name or ID
46
+ task: string, // Task description
47
+ witness: Witness, // Verification criteria
48
+ context?: Witness, // Additional context
49
+ workingDirectory?: string
50
+ });
51
+ // Returns: { taskId, teammateId, teammateName, conversationId, status: 'running' }
52
+ ```
53
+
54
+ ### await_task(input)
55
+
56
+ Wait for a task to complete. Blocks until finished or timeout.
57
+
58
+ ```typescript
59
+ const status = await ctx.majk.delegation.await_task({
60
+ taskId: string,
61
+ timeoutMs?: number // Default: no timeout
62
+ });
63
+ // Returns: DelegationTaskStatusOutput
64
+ ```
65
+
66
+ ### await_tasks(input)
67
+
68
+ Wait for multiple tasks (fan-out/fan-in pattern).
69
+
70
+ ```typescript
71
+ const results = await ctx.majk.delegation.await_tasks({
72
+ taskIds: string[],
73
+ timeoutMs?: number
74
+ });
75
+ // Returns: { results, summary: { total, completed, failed, blocked, stillRunning }, allCompleted, allSucceeded }
76
+ ```
77
+
78
+ ### check_task_status(input)
79
+
80
+ Check current status of a delegated task.
81
+
82
+ ```typescript
83
+ const status = await ctx.majk.delegation.check_task_status({
84
+ taskId: string,
85
+ messageCount?: number // Include recent messages
86
+ });
87
+ ```
88
+
89
+ ### check_witness(input)
90
+
91
+ Run a witness verification immediately.
92
+
93
+ ```typescript
94
+ const result = await ctx.majk.delegation.check_witness({
95
+ witness: Witness,
96
+ workingDirectory?: string
97
+ });
98
+ // Returns: { passed, evidence, strength, executionTimeMs }
99
+ ```
100
+
101
+ ### get_blockers(input?)
102
+
103
+ List all currently blocked tasks.
104
+
105
+ ```typescript
106
+ const { blockers, count } = await ctx.majk.delegation.get_blockers({
107
+ teammateId?: string,
108
+ assignedTo?: string
109
+ });
110
+ ```
111
+
112
+ ### resolve_blocker(input)
113
+
114
+ Resolve a blocker on a task.
115
+
116
+ ```typescript
117
+ const result = await ctx.majk.delegation.resolve_blocker({
118
+ taskId: string,
119
+ action: 'update_task' | 'update_witness' | 'send_instruction' | 'unblock',
120
+ newTask?: string,
121
+ newWitness?: Witness,
122
+ instruction?: string,
123
+ resolution?: string
124
+ });
125
+ ```
126
+
127
+ ## Witness Types
128
+
129
+ Witnesses verify task completion:
130
+
131
+ ```typescript
132
+ // Command execution
133
+ { bash: 'npm test' }
134
+ { bash: { command: 'npm test', exit_code: 0, stdout_contains: 'passed' } }
135
+
136
+ // File checks
137
+ { file: { path: 'output.json', exists: true, contains: 'success' } }
138
+
139
+ // HTTP checks
140
+ { http: { url: 'http://localhost:3000/health', status: 200 } }
141
+
142
+ // AI verification
143
+ { llm: { prompt: 'Does this code handle errors properly?', file: 'src/handler.ts' } }
144
+
145
+ // Visual verification
146
+ { vision: { image: 'screenshot.png', checklist: ['Has submit button', 'Shows form'] } }
147
+
148
+ // JavaScript
149
+ { js: { code: 'return fs.existsSync("output.txt")' } }
150
+
151
+ // Combine witnesses
152
+ { all: [{ bash: 'npm test' }, { file: { path: 'coverage.json', exists: true } }] }
153
+ { any: [{ bash: 'npm test' }, { bash: 'yarn test' }] }
154
+ ```
155
+
156
+ ## Fan-Out/Fan-In Pattern
157
+
158
+ ```typescript
159
+ // Delegate to multiple teammates in parallel
160
+ const tasks = await Promise.all([
161
+ ctx.majk.delegation.delegate_task({
162
+ teammate: 'backend-dev',
163
+ task: 'Implement the API endpoint',
164
+ witness: { bash: 'npm test -- --grep "api"' }
165
+ }),
166
+ ctx.majk.delegation.delegate_task({
167
+ teammate: 'frontend-dev',
168
+ task: 'Build the UI component',
169
+ witness: { bash: 'npm test -- --grep "ui"' }
170
+ })
171
+ ]);
172
+
173
+ // Wait for all to complete
174
+ const results = await ctx.majk.delegation.await_tasks({
175
+ taskIds: tasks.map(t => t.taskId),
176
+ timeoutMs: 300000
177
+ });
178
+
179
+ if (results.allSucceeded) {
180
+ ctx.logger.info('All tasks completed successfully');
181
+ }
182
+ ```
183
+
184
+ ## Best Practices
185
+
186
+ 1. **Clear task descriptions** - Be specific about what needs to be done
187
+ 2. **Appropriate witnesses** - Choose verification that proves completion
188
+ 3. **Handle blockers** - Monitor and resolve blocked tasks
189
+ 4. **Set timeouts** - Prevent indefinite waits
190
+ 5. **Use fan-out for parallelism** - Delegate independent tasks simultaneously
191
+
192
+ ## Next Steps
193
+
194
+ Run `npx @majkapp/plugin-kit --batch` - Batch processing API
195
+ Run `npx @majkapp/plugin-kit --tasks` - Task management API
196
+ Run `npx @majkapp/plugin-kit --teammates` - Teammate configuration
package/docs/INDEX.md CHANGED
@@ -633,8 +633,30 @@ onClick={() => {
633
633
  }}
634
634
  ```
635
635
 
636
+ ## Additional MAJK APIs
637
+
638
+ The `ctx.majk` object provides access to many powerful APIs beyond the basics covered above:
639
+
640
+ | API | Command | Description |
641
+ |-----|---------|-------------|
642
+ | **Delegation** | `--delegation` | Multi-agent task delegation with witness-based verification. Delegate tasks to teammates, fan-out/fan-in patterns, and automated completion checking. |
643
+ | **Batch** | `--batch` | Batch processing for large datasets. Process files, lists, or glob patterns with parallelism, retry logic, and progress tracking. |
644
+ | **Reports** | `--reports` | Knowledge management system with hierarchical reports, witness validation, views, and import/export capabilities. |
645
+ | **Scripting** | `--scripting` | Execute JavaScript scripts that orchestrate tool calls. Includes dry-run mode, tracing, and script re-execution. |
646
+ | **Tool Discovery** | `--tool-discovery` | Discover available service functions dynamically and invoke them. Build adaptive workflows based on available tools. |
647
+ | **Skills** | `--skills` | Register and manage skills - instructions on how to accomplish tasks using tools. Supports runtime skills with setup/teardown. |
648
+ | **Auth** | `--auth` | Core Cognito/MAJK authentication. Retrieve access tokens for calling MAJK backend services and AWS resources. |
649
+ | **Secrets** | `--secrets` | Secure secret storage with scoping (global, project, integration). Store and retrieve API keys, tokens, and credentials. |
650
+ | **Config** | `--config-api` | Access MAJK configuration using dot-notation paths. Read AWS, auth, Bedrock, and plugin settings. |
651
+ | **Plugins** | `--plugins` | Plugin lifecycle management. Install, start, stop, reload plugins programmatically. Health checks and logging. |
652
+ | **Tasks** | `--tasks` | Start and monitor asynchronous tasks. Send messages, track progress, and handle completion events. |
653
+ | **Knowledge** | `--knowledge` | Knowledge trees for organizing information. Add nodes, search, and track references across conversations. |
654
+ | **Agents** | `--agents` | Create, configure, test, and clone AI agents. Manage MCP servers and agent settings. |
655
+ | **Conversations** | `--conversations` | Access and manage conversations. List, filter, search, get messages, and subscribe to changes. |
656
+
636
657
  ## Next Steps
637
658
 
659
+ **Core Plugin Development:**
638
660
  Run `npx @majkapp/plugin-kit --functions` - Deep dive into function patterns
639
661
  Run `npx @majkapp/plugin-kit --screens` - Screen configuration details
640
662
  Run `npx @majkapp/plugin-kit --hooks` - Generated hooks reference
@@ -646,3 +668,19 @@ Run `npx @majkapp/plugin-kit --lifecycle` - onReady and cleanup
646
668
  Run `npx @majkapp/plugin-kit --testing` - Complete testing guide
647
669
  Run `npx @majkapp/plugin-kit --config` - vite.config.js and project setup
648
670
  Run `npx @majkapp/plugin-kit --full` - Complete reference
671
+
672
+ **Additional APIs:**
673
+ Run `npx @majkapp/plugin-kit --delegation` - Task delegation with witnesses
674
+ Run `npx @majkapp/plugin-kit --batch` - Batch processing
675
+ Run `npx @majkapp/plugin-kit --reports` - Knowledge management
676
+ Run `npx @majkapp/plugin-kit --scripting` - Script execution
677
+ Run `npx @majkapp/plugin-kit --tool-discovery` - Dynamic tool invocation
678
+ Run `npx @majkapp/plugin-kit --skills` - Skill management
679
+ Run `npx @majkapp/plugin-kit --auth` - Cognito authentication
680
+ Run `npx @majkapp/plugin-kit --secrets` - Secret storage
681
+ Run `npx @majkapp/plugin-kit --config-api` - Configuration access
682
+ Run `npx @majkapp/plugin-kit --plugins` - Plugin management
683
+ Run `npx @majkapp/plugin-kit --tasks` - Task monitoring
684
+ Run `npx @majkapp/plugin-kit --knowledge` - Knowledge trees
685
+ Run `npx @majkapp/plugin-kit --agents` - Agent configuration
686
+ Run `npx @majkapp/plugin-kit --conversations` - Conversation access