agents-library 1.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.
Potentially problematic release.
This version of agents-library might be problematic. Click here for more details.
- package/dist/base-agent.d.ts +172 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +255 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/base-bot.d.ts +282 -0
- package/dist/base-bot.d.ts.map +1 -0
- package/dist/base-bot.js +375 -0
- package/dist/base-bot.js.map +1 -0
- package/dist/common/result.d.ts +51 -0
- package/dist/common/result.d.ts.map +1 -0
- package/dist/common/result.js +45 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/types.d.ts +57 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +42 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/kadi-event-publisher.d.ts +163 -0
- package/dist/kadi-event-publisher.d.ts.map +1 -0
- package/dist/kadi-event-publisher.js +286 -0
- package/dist/kadi-event-publisher.js.map +1 -0
- package/dist/memory/arcadedb-adapter.d.ts +159 -0
- package/dist/memory/arcadedb-adapter.d.ts.map +1 -0
- package/dist/memory/arcadedb-adapter.js +314 -0
- package/dist/memory/arcadedb-adapter.js.map +1 -0
- package/dist/memory/file-storage-adapter.d.ts +122 -0
- package/dist/memory/file-storage-adapter.d.ts.map +1 -0
- package/dist/memory/file-storage-adapter.js +352 -0
- package/dist/memory/file-storage-adapter.js.map +1 -0
- package/dist/memory/memory-service.d.ts +208 -0
- package/dist/memory/memory-service.d.ts.map +1 -0
- package/dist/memory/memory-service.js +410 -0
- package/dist/memory/memory-service.js.map +1 -0
- package/dist/memory/types.d.ts +126 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +41 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/producer-tool-utils.d.ts +474 -0
- package/dist/producer-tool-utils.d.ts.map +1 -0
- package/dist/producer-tool-utils.js +664 -0
- package/dist/producer-tool-utils.js.map +1 -0
- package/dist/providers/anthropic-provider.d.ts +160 -0
- package/dist/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/providers/anthropic-provider.js +527 -0
- package/dist/providers/anthropic-provider.js.map +1 -0
- package/dist/providers/model-manager-provider.d.ts +91 -0
- package/dist/providers/model-manager-provider.d.ts.map +1 -0
- package/dist/providers/model-manager-provider.js +355 -0
- package/dist/providers/model-manager-provider.js.map +1 -0
- package/dist/providers/provider-manager.d.ts +111 -0
- package/dist/providers/provider-manager.d.ts.map +1 -0
- package/dist/providers/provider-manager.js +337 -0
- package/dist/providers/provider-manager.js.map +1 -0
- package/dist/providers/types.d.ts +145 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +23 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/shadow-agent-factory.d.ts +623 -0
- package/dist/shadow-agent-factory.d.ts.map +1 -0
- package/dist/shadow-agent-factory.js +1117 -0
- package/dist/shadow-agent-factory.js.map +1 -0
- package/dist/types/agent-config.d.ts +307 -0
- package/dist/types/agent-config.d.ts.map +1 -0
- package/dist/types/agent-config.js +15 -0
- package/dist/types/agent-config.js.map +1 -0
- package/dist/types/event-schemas.d.ts +358 -0
- package/dist/types/event-schemas.d.ts.map +1 -0
- package/dist/types/event-schemas.js +188 -0
- package/dist/types/event-schemas.js.map +1 -0
- package/dist/types/tool-schemas.d.ts +498 -0
- package/dist/types/tool-schemas.d.ts.map +1 -0
- package/dist/types/tool-schemas.js +457 -0
- package/dist/types/tool-schemas.js.map +1 -0
- package/dist/utils/logger.d.ts +135 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +205 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/timer.d.ts +186 -0
- package/dist/utils/timer.d.ts.map +1 -0
- package/dist/utils/timer.js +211 -0
- package/dist/utils/timer.js.map +1 -0
- package/dist/worker-agent-factory.d.ts +688 -0
- package/dist/worker-agent-factory.d.ts.map +1 -0
- package/dist/worker-agent-factory.js +1517 -0
- package/dist/worker-agent-factory.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Producer Tool Utilities
|
|
3
|
+
* ========================
|
|
4
|
+
*
|
|
5
|
+
* Shared utilities for agent-producer to invoke shrimp-task-manager tools
|
|
6
|
+
* via KĀDI broker protocol with consistent error handling and retry logic.
|
|
7
|
+
*
|
|
8
|
+
* Includes Option C orchestration pattern (Claude API streaming with tool invocation)
|
|
9
|
+
* for agent-producer workflow orchestration.
|
|
10
|
+
*
|
|
11
|
+
* Design Principles:
|
|
12
|
+
* - Standardized error classification for retry logic
|
|
13
|
+
* - Configurable timeout with sensible defaults
|
|
14
|
+
* - Type-safe result handling with discriminated unions
|
|
15
|
+
* - Graceful degradation on failure
|
|
16
|
+
* - Streaming-first architecture with tool interruption support
|
|
17
|
+
*
|
|
18
|
+
* @module producer-tool-utils
|
|
19
|
+
*/
|
|
20
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
21
|
+
import { KadiClient } from '@kadi.build/core';
|
|
22
|
+
import { ErrorType } from './types/tool-schemas.js';
|
|
23
|
+
/**
|
|
24
|
+
* Options for invokeShrimTool
|
|
25
|
+
*
|
|
26
|
+
* @property timeout - Timeout in milliseconds (default: 30000)
|
|
27
|
+
* @property targetAgent - Target agent ID (default: 'mcp-server-shrimp-agent-playground')
|
|
28
|
+
*/
|
|
29
|
+
export interface InvokeOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Timeout in milliseconds
|
|
32
|
+
* @default 30000
|
|
33
|
+
*/
|
|
34
|
+
timeout?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Target agent ID that provides the shrimp tools
|
|
37
|
+
* @default 'mcp-server-shrimp-agent-playground'
|
|
38
|
+
*/
|
|
39
|
+
targetAgent?: string;
|
|
40
|
+
/**
|
|
41
|
+
* KadiClient instance for async response handling (optional)
|
|
42
|
+
* Required if the tool returns {status: "pending"} and you want to wait for the async result
|
|
43
|
+
*/
|
|
44
|
+
client?: KadiClient;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Structured result from shrimp tool invocation
|
|
48
|
+
*
|
|
49
|
+
* Uses discriminated union pattern for type-safe error handling.
|
|
50
|
+
* Different from types/tool-schemas.ts ToolInvocationResult which is for KĀDI protocol.
|
|
51
|
+
*/
|
|
52
|
+
export interface ShrimpToolResult {
|
|
53
|
+
/**
|
|
54
|
+
* Success flag - use for type narrowing
|
|
55
|
+
*/
|
|
56
|
+
success: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Result data (present when success=true)
|
|
59
|
+
*/
|
|
60
|
+
data?: any;
|
|
61
|
+
/**
|
|
62
|
+
* Error details (present when success=false)
|
|
63
|
+
*/
|
|
64
|
+
error?: {
|
|
65
|
+
/**
|
|
66
|
+
* Error classification for retry logic
|
|
67
|
+
*/
|
|
68
|
+
type: ErrorType;
|
|
69
|
+
/**
|
|
70
|
+
* Human-readable error message
|
|
71
|
+
*/
|
|
72
|
+
message: string;
|
|
73
|
+
/**
|
|
74
|
+
* Original error object (if available)
|
|
75
|
+
*/
|
|
76
|
+
original?: Error;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Invoke shrimp-task-manager tool via KĀDI broker protocol
|
|
81
|
+
*
|
|
82
|
+
* Provides consistent error handling, timeout management, and error classification
|
|
83
|
+
* for tools exposed by shrimp-task-manager MCP server. Uses KĀDI protocol.invokeTool()
|
|
84
|
+
* with standardized response handling.
|
|
85
|
+
*
|
|
86
|
+
* Error Classification:
|
|
87
|
+
* - **Transient errors** (retry recommended):
|
|
88
|
+
* - Network errors (ECONNREFUSED, ENOTFOUND)
|
|
89
|
+
* - Timeout errors
|
|
90
|
+
* - Rate limiting (429)
|
|
91
|
+
* - Service unavailable (503)
|
|
92
|
+
*
|
|
93
|
+
* - **Permanent errors** (fail-fast):
|
|
94
|
+
* - Validation errors (400)
|
|
95
|
+
* - Authentication errors (401, 403)
|
|
96
|
+
* - Not found errors (404)
|
|
97
|
+
* - Invalid input errors
|
|
98
|
+
*
|
|
99
|
+
* Response Handling:
|
|
100
|
+
* - Success (200-299): Returns { success: true, data: responseData }
|
|
101
|
+
* - Client error (400-499): Returns { success: false, error: { type: 'permanent', message } }
|
|
102
|
+
* - Server error (500-599): Returns { success: false, error: { type: 'transient', message } }
|
|
103
|
+
* - Network error: Returns { success: false, error: { type: 'transient', message } }
|
|
104
|
+
*
|
|
105
|
+
* @param protocol - KĀDI broker protocol instance (from client.getBrokerProtocol())
|
|
106
|
+
* @param toolName - Name of shrimp tool to invoke (e.g., 'shrimp_plan_task')
|
|
107
|
+
* @param params - Tool input parameters (validated by tool's input schema)
|
|
108
|
+
* @param options - Optional configuration (timeout, targetAgent)
|
|
109
|
+
* @returns Structured result with success flag and data/error
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Success case
|
|
114
|
+
* const result = await invokeShrimTool(
|
|
115
|
+
* protocol,
|
|
116
|
+
* 'shrimp_plan_task',
|
|
117
|
+
* { description: 'Implement feature X', requirements: 'Must be async' }
|
|
118
|
+
* );
|
|
119
|
+
*
|
|
120
|
+
* if (result.success) {
|
|
121
|
+
* console.log('Task planned:', result.data);
|
|
122
|
+
* } else {
|
|
123
|
+
* if (result.error.type === ErrorType.Transient) {
|
|
124
|
+
* // Retry with exponential backoff
|
|
125
|
+
* await retryWithBackoff(() => invokeShrimTool(...));
|
|
126
|
+
* } else {
|
|
127
|
+
* // Fail-fast on permanent errors
|
|
128
|
+
* console.error('Permanent error:', result.error.message);
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // With custom timeout
|
|
136
|
+
* const result = await invokeShrimTool(
|
|
137
|
+
* protocol,
|
|
138
|
+
* 'shrimp_execute_task',
|
|
139
|
+
* { taskId: '123' },
|
|
140
|
+
* { timeout: 60000 } // 60 seconds
|
|
141
|
+
* );
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // With custom target agent
|
|
147
|
+
* const result = await invokeShrimTool(
|
|
148
|
+
* protocol,
|
|
149
|
+
* 'shrimp_split_tasks',
|
|
150
|
+
* { tasksRaw: JSON.stringify([...]), updateMode: 'append' },
|
|
151
|
+
* { targetAgent: 'mcp-server-shrimp-custom' }
|
|
152
|
+
* );
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function invokeShrimTool(protocol: any, toolName: string, params: any, options?: InvokeOptions): Promise<ShrimpToolResult>;
|
|
156
|
+
/**
|
|
157
|
+
* Type guard to check if result is a success
|
|
158
|
+
*
|
|
159
|
+
* @param result - Tool invocation result
|
|
160
|
+
* @returns True if result is success
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* if (isToolSuccess(result)) {
|
|
165
|
+
* console.log('Success:', result.data);
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function isToolSuccess(result: ShrimpToolResult): result is ShrimpToolResult & {
|
|
170
|
+
success: true;
|
|
171
|
+
data: any;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Type guard to check if result is a failure
|
|
175
|
+
*
|
|
176
|
+
* @param result - Tool invocation result
|
|
177
|
+
* @returns True if result is failure
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* if (isToolFailure(result)) {
|
|
182
|
+
* console.error('Failure:', result.error.message);
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare function isToolFailure(result: ShrimpToolResult): result is ShrimpToolResult & {
|
|
187
|
+
success: false;
|
|
188
|
+
error: {
|
|
189
|
+
type: ErrorType;
|
|
190
|
+
message: string;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Tool definition for Claude API
|
|
195
|
+
*
|
|
196
|
+
* Matches Anthropic SDK tool definition structure.
|
|
197
|
+
*/
|
|
198
|
+
export interface ToolDefinition {
|
|
199
|
+
/**
|
|
200
|
+
* Tool name (must be unique)
|
|
201
|
+
*/
|
|
202
|
+
name: string;
|
|
203
|
+
/**
|
|
204
|
+
* Human-readable tool description for Claude
|
|
205
|
+
*/
|
|
206
|
+
description: string;
|
|
207
|
+
/**
|
|
208
|
+
* Input schema using JSON Schema format
|
|
209
|
+
*/
|
|
210
|
+
input_schema: {
|
|
211
|
+
type: 'object';
|
|
212
|
+
properties: Record<string, any>;
|
|
213
|
+
required?: string[];
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Record of a tool invocation during orchestration
|
|
218
|
+
*
|
|
219
|
+
* Used for debugging and analysis of tool usage patterns.
|
|
220
|
+
*/
|
|
221
|
+
export interface ToolInvocation {
|
|
222
|
+
/**
|
|
223
|
+
* Tool name that was invoked
|
|
224
|
+
*/
|
|
225
|
+
toolName: string;
|
|
226
|
+
/**
|
|
227
|
+
* Input parameters passed to tool
|
|
228
|
+
*/
|
|
229
|
+
input: any;
|
|
230
|
+
/**
|
|
231
|
+
* Result returned from tool (success or error)
|
|
232
|
+
*/
|
|
233
|
+
result: ShrimpToolResult;
|
|
234
|
+
/**
|
|
235
|
+
* Timestamp when tool was invoked
|
|
236
|
+
*/
|
|
237
|
+
timestamp: string;
|
|
238
|
+
/**
|
|
239
|
+
* Duration of tool invocation in milliseconds
|
|
240
|
+
*/
|
|
241
|
+
durationMs: number;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Options for orchestrateWithClaude
|
|
245
|
+
*/
|
|
246
|
+
export interface OrchestrationOptions {
|
|
247
|
+
/**
|
|
248
|
+
* Maximum tokens for Claude response
|
|
249
|
+
* @default 8000
|
|
250
|
+
*/
|
|
251
|
+
max_tokens?: number;
|
|
252
|
+
/**
|
|
253
|
+
* Temperature for Claude response (0-1)
|
|
254
|
+
* @default 1.0
|
|
255
|
+
*/
|
|
256
|
+
temperature?: number;
|
|
257
|
+
/**
|
|
258
|
+
* System prompts for Claude
|
|
259
|
+
* @default []
|
|
260
|
+
*/
|
|
261
|
+
system?: string[];
|
|
262
|
+
/**
|
|
263
|
+
* Claude model to use
|
|
264
|
+
* @default 'claude-sonnet-4-5-20250929'
|
|
265
|
+
*/
|
|
266
|
+
model?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Timeout for tool invocations in milliseconds
|
|
269
|
+
* @default 30000
|
|
270
|
+
*/
|
|
271
|
+
toolTimeout?: number;
|
|
272
|
+
/**
|
|
273
|
+
* Target agent for tool invocations
|
|
274
|
+
* @default 'mcp-server-shrimp-agent-playground'
|
|
275
|
+
*/
|
|
276
|
+
targetAgent?: string;
|
|
277
|
+
/**
|
|
278
|
+
* KadiClient instance for async response handling (optional)
|
|
279
|
+
* Required if tools return {status: "pending"} and you want to wait for async results
|
|
280
|
+
*/
|
|
281
|
+
client?: KadiClient;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Result from orchestrateWithClaude
|
|
285
|
+
*/
|
|
286
|
+
export interface OrchestrationResult {
|
|
287
|
+
/**
|
|
288
|
+
* Accumulated text response from Claude
|
|
289
|
+
*/
|
|
290
|
+
text: string;
|
|
291
|
+
/**
|
|
292
|
+
* Log of all tool invocations during orchestration
|
|
293
|
+
*/
|
|
294
|
+
toolInvocations: ToolInvocation[];
|
|
295
|
+
/**
|
|
296
|
+
* Whether orchestration completed successfully
|
|
297
|
+
*/
|
|
298
|
+
success: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Error message if orchestration failed
|
|
301
|
+
*/
|
|
302
|
+
error?: string;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Orchestrate workflow using Claude API streaming with tool invocation (Option C pattern)
|
|
306
|
+
*
|
|
307
|
+
* Implements agent-producer Option C orchestration flow:
|
|
308
|
+
* 1. Stream Claude API response with tool definitions
|
|
309
|
+
* 2. When Claude requests tool use, pause stream
|
|
310
|
+
* 3. Invoke tool via invokeShrimTool() with KĀDI protocol
|
|
311
|
+
* 4. Resume stream with tool_result
|
|
312
|
+
* 5. Accumulate text blocks for final response
|
|
313
|
+
* 6. Log all tool invocations for debugging
|
|
314
|
+
*
|
|
315
|
+
* Streaming Architecture:
|
|
316
|
+
* - Uses Anthropic SDK streaming API for low-latency responses
|
|
317
|
+
* - Handles streaming interruptions gracefully (tool_use blocks)
|
|
318
|
+
* - Accumulates partial text blocks into final response
|
|
319
|
+
* - Maintains tool invocation log for analysis
|
|
320
|
+
*
|
|
321
|
+
* Error Handling:
|
|
322
|
+
* - Tool invocation failures are passed back to Claude as error tool_result
|
|
323
|
+
* - Stream errors are caught and returned in OrchestrationResult
|
|
324
|
+
* - Graceful degradation if tool invocation fails
|
|
325
|
+
*
|
|
326
|
+
* @param anthropic - Anthropic SDK client instance
|
|
327
|
+
* @param protocol - KĀDI broker protocol instance (from client.getBrokerProtocol())
|
|
328
|
+
* @param prompt - User prompt to send to Claude
|
|
329
|
+
* @param availableTools - Array of tool definitions Claude can use
|
|
330
|
+
* @param options - Optional configuration (max_tokens, temperature, system prompts, etc.)
|
|
331
|
+
* @returns Orchestration result with accumulated text and tool invocation log
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* // Basic usage
|
|
336
|
+
* const result = await orchestrateWithClaude(
|
|
337
|
+
* anthropic,
|
|
338
|
+
* protocol,
|
|
339
|
+
* 'Plan a task to implement feature X',
|
|
340
|
+
* [
|
|
341
|
+
* {
|
|
342
|
+
* name: 'shrimp_plan_task',
|
|
343
|
+
* description: 'Create task plan with requirements',
|
|
344
|
+
* input_schema: {
|
|
345
|
+
* type: 'object',
|
|
346
|
+
* properties: {
|
|
347
|
+
* description: { type: 'string' },
|
|
348
|
+
* requirements: { type: 'string' }
|
|
349
|
+
* },
|
|
350
|
+
* required: ['description']
|
|
351
|
+
* }
|
|
352
|
+
* }
|
|
353
|
+
* ]
|
|
354
|
+
* );
|
|
355
|
+
*
|
|
356
|
+
* if (result.success) {
|
|
357
|
+
* console.log('Claude response:', result.text);
|
|
358
|
+
* console.log('Tools invoked:', result.toolInvocations.length);
|
|
359
|
+
* }
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* // With custom options
|
|
365
|
+
* const result = await orchestrateWithClaude(
|
|
366
|
+
* anthropic,
|
|
367
|
+
* protocol,
|
|
368
|
+
* 'Split tasks for feature implementation',
|
|
369
|
+
* tools,
|
|
370
|
+
* {
|
|
371
|
+
* max_tokens: 16000,
|
|
372
|
+
* temperature: 0.7,
|
|
373
|
+
* system: ['You are a task planning assistant'],
|
|
374
|
+
* toolTimeout: 60000
|
|
375
|
+
* }
|
|
376
|
+
* );
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
export declare function orchestrateWithClaude(anthropic: Anthropic, protocol: any, prompt: string, availableTools: ToolDefinition[], options?: OrchestrationOptions): Promise<OrchestrationResult>;
|
|
380
|
+
/**
|
|
381
|
+
* Metadata for tool event publication
|
|
382
|
+
*
|
|
383
|
+
* Required fields for standardized tool event structure across agent-producer.
|
|
384
|
+
*/
|
|
385
|
+
export interface EventMetadata {
|
|
386
|
+
/**
|
|
387
|
+
* Tool name that triggered the event
|
|
388
|
+
*/
|
|
389
|
+
toolName: string;
|
|
390
|
+
/**
|
|
391
|
+
* Optional task ID associated with the tool invocation
|
|
392
|
+
*/
|
|
393
|
+
taskId?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Agent name publishing the event
|
|
396
|
+
* @default 'producer'
|
|
397
|
+
*/
|
|
398
|
+
agentName?: string;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Publish standardized tool event to KĀDI broker
|
|
402
|
+
*
|
|
403
|
+
* Creates consistent event structure across all agent-producer tools with
|
|
404
|
+
* required metadata fields (timestamp, agentName, toolName, taskId).
|
|
405
|
+
*
|
|
406
|
+
* Topic Pattern: producer.tool.{eventType}
|
|
407
|
+
* - producer.tool.invoked - Tool invocation started
|
|
408
|
+
* - producer.tool.completed - Tool completed successfully
|
|
409
|
+
* - producer.tool.failed - Tool invocation failed
|
|
410
|
+
*
|
|
411
|
+
* Event Structure:
|
|
412
|
+
* ```typescript
|
|
413
|
+
* {
|
|
414
|
+
* timestamp: string; // ISO 8601 timestamp
|
|
415
|
+
* agentName: string; // 'producer' (default)
|
|
416
|
+
* toolName: string; // Tool that was invoked
|
|
417
|
+
* taskId?: string; // Optional task ID
|
|
418
|
+
* ...data // Additional event data
|
|
419
|
+
* }
|
|
420
|
+
* ```
|
|
421
|
+
*
|
|
422
|
+
* Validation:
|
|
423
|
+
* - Topic pattern validated using validateTopicPattern()
|
|
424
|
+
* - Ensures backward compatibility with existing event conventions
|
|
425
|
+
*
|
|
426
|
+
* Error Handling:
|
|
427
|
+
* - Invalid topic patterns logged as warnings
|
|
428
|
+
* - Publishing failures logged but do not throw
|
|
429
|
+
* - Graceful degradation if broker unavailable
|
|
430
|
+
*
|
|
431
|
+
* @param client - KĀDI client instance (from KadiClient)
|
|
432
|
+
* @param eventType - Event type suffix (e.g., 'invoked', 'completed', 'failed')
|
|
433
|
+
* @param data - Event data payload (will be merged with metadata)
|
|
434
|
+
* @param metadata - Required metadata (toolName, optional taskId, agentName)
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```typescript
|
|
438
|
+
* // Publish tool invocation event
|
|
439
|
+
* await publishToolEvent(
|
|
440
|
+
* client,
|
|
441
|
+
* 'invoked',
|
|
442
|
+
* { input: { description: 'Plan feature X' } },
|
|
443
|
+
* { toolName: 'shrimp_plan_task', taskId: 'task-123' }
|
|
444
|
+
* );
|
|
445
|
+
* // Topic: producer.tool.invoked
|
|
446
|
+
* // Payload: { timestamp, agentName: 'producer', toolName, taskId, input: {...} }
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* // Publish tool completion event
|
|
452
|
+
* await publishToolEvent(
|
|
453
|
+
* client,
|
|
454
|
+
* 'completed',
|
|
455
|
+
* { result: { success: true, data: {...} }, durationMs: 1500 },
|
|
456
|
+
* { toolName: 'shrimp_execute_task', taskId: 'task-456' }
|
|
457
|
+
* );
|
|
458
|
+
* // Topic: producer.tool.completed
|
|
459
|
+
* ```
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* // Publish tool failure event
|
|
464
|
+
* await publishToolEvent(
|
|
465
|
+
* client,
|
|
466
|
+
* 'failed',
|
|
467
|
+
* { error: 'Validation failed', errorType: 'permanent' },
|
|
468
|
+
* { toolName: 'shrimp_split_tasks', taskId: 'task-789' }
|
|
469
|
+
* );
|
|
470
|
+
* // Topic: producer.tool.failed
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
export declare function publishToolEvent(client: KadiClient, eventType: string, data: any, metadata: EventMetadata): Promise<void>;
|
|
474
|
+
//# sourceMappingURL=producer-tool-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"producer-tool-utils.d.ts","sourceRoot":"","sources":["../src/producer-tool-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAqB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AA4FvE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAA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