@aumos/agent-mesh-router 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.
@@ -0,0 +1,106 @@
1
+ /**
2
+ * HTTP client for the agent-mesh-router service API.
3
+ *
4
+ * Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
5
+ * No external dependencies required.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createAgentMeshRouterClient } from "@aumos/agent-mesh-router";
10
+ *
11
+ * const client = createAgentMeshRouterClient({ baseUrl: "http://localhost:8080" });
12
+ *
13
+ * // Send a task message to an agent
14
+ * const result = await client.sendMessage({
15
+ * recipient_id: "summarizer-agent",
16
+ * message_type: "task",
17
+ * payload: { text: "Summarize the quarterly report." },
18
+ * });
19
+ *
20
+ * if (result.ok) {
21
+ * console.log("Message dispatched:", result.data.message_id);
22
+ * }
23
+ *
24
+ * // Execute a sequential workflow
25
+ * const workflow = await client.routeTask({
26
+ * pattern: "sequential",
27
+ * steps: [
28
+ * { agent_id: "reader", action: "extract", params: {}, timeout_seconds: 30, depends_on: [] },
29
+ * { agent_id: "writer", action: "summarize", params: {}, timeout_seconds: 60, depends_on: [] },
30
+ * ],
31
+ * });
32
+ * ```
33
+ */
34
+ import type { AgentRoute, ApiResult, CircuitBreakerStatus, ConflictResolution, Message, MeshTopology, ResolveConflictRequest, RouteTaskRequest, SendMessageRequest } from "./types.js";
35
+ /** Configuration options for the AgentMeshRouterClient. */
36
+ export interface AgentMeshRouterClientConfig {
37
+ /** Base URL of the agent-mesh-router server (e.g. "http://localhost:8080"). */
38
+ readonly baseUrl: string;
39
+ /** Optional request timeout in milliseconds (default: 30000). */
40
+ readonly timeoutMs?: number;
41
+ /** Optional extra HTTP headers sent with every request. */
42
+ readonly headers?: Readonly<Record<string, string>>;
43
+ }
44
+ /** Typed HTTP client for the agent-mesh-router service. */
45
+ export interface AgentMeshRouterClient {
46
+ /**
47
+ * Dispatch a message to a target agent in the mesh.
48
+ *
49
+ * Supports all MessageType variants (task, query, broadcast, etc.).
50
+ * Returns the created Message record including the assigned message_id.
51
+ *
52
+ * @param request - Message dispatch payload with recipient and type.
53
+ * @returns The created Message record with message_id and metadata.
54
+ */
55
+ sendMessage(request: SendMessageRequest): Promise<ApiResult<Message>>;
56
+ /**
57
+ * Execute a multi-step workflow through the agent mesh.
58
+ *
59
+ * The workflow pattern controls how steps are coordinated:
60
+ * - sequential: steps run one after another in order
61
+ * - parallel: all steps run concurrently with fan-out/fan-in
62
+ * - hierarchical: a supervisor agent delegates to sub-agents
63
+ * - competitive: all steps race; first result wins
64
+ * - consensus: results are collected and voted upon
65
+ *
66
+ * @param request - Workflow execution request with pattern and steps.
67
+ * @returns AgentRoute with per-step results, status, and total duration.
68
+ */
69
+ routeTask(request: RouteTaskRequest): Promise<ApiResult<AgentRoute>>;
70
+ /**
71
+ * Retrieve the current mesh topology including all registered agent nodes.
72
+ *
73
+ * @returns MeshTopology snapshot with nodes, counts, and capture timestamp.
74
+ */
75
+ getTopology(): Promise<ApiResult<MeshTopology>>;
76
+ /**
77
+ * Retrieve the status of a named circuit breaker.
78
+ *
79
+ * Circuit breakers protect mesh routes from cascading failures. This
80
+ * endpoint returns the current state (closed/open/half_open) and
81
+ * cumulative call/rejection counts.
82
+ *
83
+ * @param circuitName - The human-readable circuit breaker name.
84
+ * @returns CircuitBreakerStatus snapshot with state and counters.
85
+ */
86
+ getCircuitBreakerStatus(circuitName: string): Promise<ApiResult<CircuitBreakerStatus>>;
87
+ /**
88
+ * Resolve a conflict between competing agent outputs.
89
+ *
90
+ * Used after competitive or consensus workflows produce disagreeing results.
91
+ * The configured resolution strategy (majority, weighted, supervisor, etc.)
92
+ * determines how a winner is selected or synthesized.
93
+ *
94
+ * @param request - Conflict resolution request with competing outputs.
95
+ * @returns ConflictResolution with the resolved output and winning agent.
96
+ */
97
+ resolveConflict(request: ResolveConflictRequest): Promise<ApiResult<ConflictResolution>>;
98
+ }
99
+ /**
100
+ * Create a typed HTTP client for the agent-mesh-router service.
101
+ *
102
+ * @param config - Client configuration including base URL.
103
+ * @returns An AgentMeshRouterClient instance.
104
+ */
105
+ export declare function createAgentMeshRouterClient(config: AgentMeshRouterClientConfig): AgentMeshRouterClient;
106
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EACV,UAAU,EAEV,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,2DAA2D;AAC3D,MAAM,WAAW,2BAA2B;IAC1C,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD;AA0DD,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAEtE;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IAErE;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IAEhD;;;;;;;;;OASG;IACH,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAEvF;;;;;;;;;OASG;IACH,eAAe,CACb,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC;CAC3C;AAMD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,2BAA2B,GAClC,qBAAqB,CA+DvB"}
package/dist/client.js ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * HTTP client for the agent-mesh-router service API.
3
+ *
4
+ * Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
5
+ * No external dependencies required.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createAgentMeshRouterClient } from "@aumos/agent-mesh-router";
10
+ *
11
+ * const client = createAgentMeshRouterClient({ baseUrl: "http://localhost:8080" });
12
+ *
13
+ * // Send a task message to an agent
14
+ * const result = await client.sendMessage({
15
+ * recipient_id: "summarizer-agent",
16
+ * message_type: "task",
17
+ * payload: { text: "Summarize the quarterly report." },
18
+ * });
19
+ *
20
+ * if (result.ok) {
21
+ * console.log("Message dispatched:", result.data.message_id);
22
+ * }
23
+ *
24
+ * // Execute a sequential workflow
25
+ * const workflow = await client.routeTask({
26
+ * pattern: "sequential",
27
+ * steps: [
28
+ * { agent_id: "reader", action: "extract", params: {}, timeout_seconds: 30, depends_on: [] },
29
+ * { agent_id: "writer", action: "summarize", params: {}, timeout_seconds: 60, depends_on: [] },
30
+ * ],
31
+ * });
32
+ * ```
33
+ */
34
+ // ---------------------------------------------------------------------------
35
+ // Internal helpers
36
+ // ---------------------------------------------------------------------------
37
+ async function fetchJson(url, init, timeoutMs) {
38
+ const controller = new AbortController();
39
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
40
+ try {
41
+ const response = await fetch(url, { ...init, signal: controller.signal });
42
+ clearTimeout(timeoutId);
43
+ const body = await response.json();
44
+ if (!response.ok) {
45
+ const errorBody = body;
46
+ return {
47
+ ok: false,
48
+ error: {
49
+ error: errorBody.error ?? "Unknown error",
50
+ detail: errorBody.detail ?? "",
51
+ },
52
+ status: response.status,
53
+ };
54
+ }
55
+ return { ok: true, data: body };
56
+ }
57
+ catch (err) {
58
+ clearTimeout(timeoutId);
59
+ const message = err instanceof Error ? err.message : String(err);
60
+ return {
61
+ ok: false,
62
+ error: { error: "Network error", detail: message },
63
+ status: 0,
64
+ };
65
+ }
66
+ }
67
+ function buildHeaders(extraHeaders) {
68
+ return {
69
+ "Content-Type": "application/json",
70
+ Accept: "application/json",
71
+ ...extraHeaders,
72
+ };
73
+ }
74
+ // ---------------------------------------------------------------------------
75
+ // Client factory
76
+ // ---------------------------------------------------------------------------
77
+ /**
78
+ * Create a typed HTTP client for the agent-mesh-router service.
79
+ *
80
+ * @param config - Client configuration including base URL.
81
+ * @returns An AgentMeshRouterClient instance.
82
+ */
83
+ export function createAgentMeshRouterClient(config) {
84
+ const { baseUrl, timeoutMs = 30000, headers: extraHeaders } = config;
85
+ const baseHeaders = buildHeaders(extraHeaders);
86
+ return {
87
+ async sendMessage(request) {
88
+ return fetchJson(`${baseUrl}/messages`, {
89
+ method: "POST",
90
+ headers: baseHeaders,
91
+ body: JSON.stringify(request),
92
+ }, timeoutMs);
93
+ },
94
+ async routeTask(request) {
95
+ return fetchJson(`${baseUrl}/workflows`, {
96
+ method: "POST",
97
+ headers: baseHeaders,
98
+ body: JSON.stringify(request),
99
+ }, timeoutMs);
100
+ },
101
+ async getTopology() {
102
+ return fetchJson(`${baseUrl}/topology`, { method: "GET", headers: baseHeaders }, timeoutMs);
103
+ },
104
+ async getCircuitBreakerStatus(circuitName) {
105
+ return fetchJson(`${baseUrl}/circuit-breakers/${encodeURIComponent(circuitName)}`, { method: "GET", headers: baseHeaders }, timeoutMs);
106
+ },
107
+ async resolveConflict(request) {
108
+ return fetchJson(`${baseUrl}/conflicts/resolve`, {
109
+ method: "POST",
110
+ headers: baseHeaders,
111
+ body: JSON.stringify(request),
112
+ }, timeoutMs);
113
+ },
114
+ };
115
+ }
116
+ //# sourceMappingURL=client.js.map
@@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,OAAO,qBAAqB,kBAAkB,CAAC,WAAW,CAAC,EAAE,EAChE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,EACvC,SAAS,CACV,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,eAAe,CACnB,OAA+B;YAE/B,OAAO,SAAS,CACd,GAAG,OAAO,oBAAoB,EAC9B;gBACE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,WAAW;gBACpB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAC9B,EACD,SAAS,CACV,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @aumos/agent-mesh-router
3
+ *
4
+ * TypeScript client for the AumOS agent-mesh-router service.
5
+ * Provides HTTP client and type definitions for multi-agent messaging,
6
+ * workflow orchestration, circuit breaker inspection, and conflict resolution.
7
+ */
8
+ export type { AgentMeshRouterClient, AgentMeshRouterClientConfig } from "./client.js";
9
+ export { createAgentMeshRouterClient } from "./client.js";
10
+ export type { MessageType, MessagePriority, Message, SendMessageRequest, WorkflowPattern, WorkflowStep, StepResult, WorkflowStatus, AgentRoute, RouteTaskRequest, AgentStatus, MeshNode, MeshTopology, CircuitBreakerState, CircuitBreakerStatus, ResolveConflictRequest, ConflictResolution, RoutingConfig, ApiError, ApiResult, } from "./types.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAG1D,YAAY,EACV,WAAW,EACX,eAAe,EACf,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @aumos/agent-mesh-router
3
+ *
4
+ * TypeScript client for the AumOS agent-mesh-router service.
5
+ * Provides HTTP client and type definitions for multi-agent messaging,
6
+ * workflow orchestration, circuit breaker inspection, and conflict resolution.
7
+ */
8
+ export { createAgentMeshRouterClient } from "./client.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,249 @@
1
+ /**
2
+ * TypeScript interfaces for the agent-mesh-router service.
3
+ *
4
+ * Mirrors the Python dataclasses and enums defined in:
5
+ * agent_mesh_router.messages.types
6
+ * agent_mesh_router.workflows.base
7
+ * agent_mesh_router.routing.table
8
+ * agent_mesh_router.fleet.registry
9
+ * agent_mesh_router.resilience.circuit_breaker
10
+ *
11
+ * All interfaces use readonly fields to match Python's frozen dataclasses.
12
+ */
13
+ /**
14
+ * Discriminator for inter-agent message semantics.
15
+ * Maps to MessageType enum in agent_mesh_router.messages.types.
16
+ */
17
+ export type MessageType = "task" | "query" | "response" | "result" | "handoff" | "broadcast" | "heartbeat" | "error" | "cancel" | "ack";
18
+ /**
19
+ * Message priority levels compatible with asyncio.PriorityQueue ordering.
20
+ * Lower numeric values are processed first.
21
+ * Maps to Priority enum in agent_mesh_router.messages.types.
22
+ */
23
+ export type MessagePriority = "CRITICAL" | "HIGH" | "NORMAL" | "LOW" | "BATCH";
24
+ /**
25
+ * An inter-agent message routed through the mesh.
26
+ * Encompasses all MessageType variants.
27
+ */
28
+ export interface Message {
29
+ /** Unique message identifier (UUID4). */
30
+ readonly message_id: string;
31
+ /** Discriminator for message semantics. */
32
+ readonly message_type: MessageType;
33
+ /** Agent identifier of the sender. */
34
+ readonly sender_id: string;
35
+ /** Agent identifier of the intended recipient (empty for broadcasts). */
36
+ readonly recipient_id: string;
37
+ /** Message payload — arbitrary key-value pairs. */
38
+ readonly payload: Readonly<Record<string, unknown>>;
39
+ /** Priority level controlling queue ordering. */
40
+ readonly priority: MessagePriority;
41
+ /** ISO-8601 UTC timestamp when the message was created. */
42
+ readonly created_at: string;
43
+ /** Optional correlation ID linking related messages (e.g. request/response). */
44
+ readonly correlation_id?: string;
45
+ /** Optional topic string used for broadcast fan-out. */
46
+ readonly topic?: string;
47
+ }
48
+ /**
49
+ * Request payload for dispatching a message into the mesh.
50
+ */
51
+ export interface SendMessageRequest {
52
+ /** Target agent identifier. */
53
+ readonly recipient_id: string;
54
+ /** Message type discriminator. */
55
+ readonly message_type: MessageType;
56
+ /** Message payload. */
57
+ readonly payload: Readonly<Record<string, unknown>>;
58
+ /** Priority level (default "NORMAL"). */
59
+ readonly priority?: MessagePriority;
60
+ /** Optional correlation ID for request/response linking. */
61
+ readonly correlation_id?: string;
62
+ }
63
+ /**
64
+ * Workflow coordination pattern.
65
+ * Maps to WorkflowExecutor subclass names in agent_mesh_router.workflows.
66
+ */
67
+ export type WorkflowPattern = "sequential" | "parallel" | "hierarchical" | "competitive" | "consensus";
68
+ /**
69
+ * A single step within a workflow.
70
+ * Maps to WorkflowStep dataclass in agent_mesh_router.workflows.base.
71
+ */
72
+ export interface WorkflowStep {
73
+ /** Unique identifier for this step (UUID4). */
74
+ readonly step_id: string;
75
+ /** Agent responsible for executing this step. */
76
+ readonly agent_id: string;
77
+ /** Action or operation name (e.g. "summarize", "translate"). */
78
+ readonly action: string;
79
+ /** Parameters passed to the agent for this action. */
80
+ readonly params: Readonly<Record<string, unknown>>;
81
+ /** Maximum seconds allowed for this step (null = no per-step timeout). */
82
+ readonly timeout_seconds: number | null;
83
+ /** step_id values that must complete before this step may execute. */
84
+ readonly depends_on: readonly string[];
85
+ }
86
+ /**
87
+ * Outcome of executing a single WorkflowStep.
88
+ * Maps to StepResult dataclass in agent_mesh_router.workflows.base.
89
+ */
90
+ export interface StepResult {
91
+ /** Matches the WorkflowStep.step_id that produced this result. */
92
+ readonly step_id: string;
93
+ /** True when the step completed without error. */
94
+ readonly success: boolean;
95
+ /** Data returned by the agent for this step (null on failure). */
96
+ readonly output: Readonly<Record<string, unknown>> | null;
97
+ /** Wall-clock milliseconds taken to execute this step. */
98
+ readonly duration_ms: number;
99
+ /** Error description when success is false (null on success). */
100
+ readonly error: string | null;
101
+ }
102
+ /**
103
+ * Overall status of a workflow execution.
104
+ * Maps to WorkflowStatus enum in agent_mesh_router.workflows.base.
105
+ */
106
+ export type WorkflowStatus = "success" | "partial" | "failed" | "cancelled";
107
+ /**
108
+ * Aggregate outcome of a complete workflow execution.
109
+ * Maps to WorkflowResult dataclass in agent_mesh_router.workflows.base.
110
+ */
111
+ export interface AgentRoute {
112
+ /** Unique identifier for this workflow run (UUID4). */
113
+ readonly workflow_id: string;
114
+ /** Ordered list of individual step outcomes. */
115
+ readonly step_results: readonly StepResult[];
116
+ /** Overall workflow status. */
117
+ readonly status: WorkflowStatus;
118
+ /** Total wall-clock milliseconds from first step start to last step end. */
119
+ readonly duration_ms: number;
120
+ }
121
+ /**
122
+ * Request payload for executing a multi-step workflow through the mesh.
123
+ */
124
+ export interface RouteTaskRequest {
125
+ /** Coordination pattern for this workflow. */
126
+ readonly pattern: WorkflowPattern;
127
+ /** Ordered list of steps to execute. */
128
+ readonly steps: readonly Omit<WorkflowStep, "step_id">[];
129
+ /** Optional workflow-level timeout in seconds. */
130
+ readonly timeout_seconds?: number;
131
+ }
132
+ /**
133
+ * Lifecycle status of an agent node in the fleet.
134
+ * Maps to AgentStatus enum in agent_mesh_router.fleet.registry.
135
+ */
136
+ export type AgentStatus = "HEALTHY" | "UNHEALTHY" | "DEGRADED" | "STARTING" | "STOPPING";
137
+ /**
138
+ * A single agent node in the fleet registry.
139
+ * Maps to AgentNode dataclass in agent_mesh_router.fleet.registry.
140
+ */
141
+ export interface MeshNode {
142
+ /** Unique agent identifier. */
143
+ readonly agent_id: string;
144
+ /** Capability strings this agent exposes. */
145
+ readonly capabilities: readonly string[];
146
+ /** Current lifecycle status. */
147
+ readonly status: AgentStatus;
148
+ /** Normalized load in [0.0, 1.0]; 0.0 = idle, 1.0 = fully loaded. */
149
+ readonly load_score: number;
150
+ /** Unix epoch seconds of the most recent heartbeat received. */
151
+ readonly last_heartbeat: number;
152
+ /** Free-form key-value metadata (region, version, model, etc.). */
153
+ readonly metadata: Readonly<Record<string, string>>;
154
+ }
155
+ /**
156
+ * Snapshot of the full mesh topology returned by getTopology().
157
+ */
158
+ export interface MeshTopology {
159
+ /** All currently registered agent nodes. */
160
+ readonly nodes: readonly MeshNode[];
161
+ /** Total number of registered nodes. */
162
+ readonly total_count: number;
163
+ /** Number of nodes with HEALTHY status. */
164
+ readonly healthy_count: number;
165
+ /** ISO-8601 UTC timestamp when this snapshot was captured. */
166
+ readonly captured_at: string;
167
+ }
168
+ /**
169
+ * Possible states of a circuit breaker.
170
+ * Maps to CircuitState enum in agent_mesh_router.resilience.circuit_breaker.
171
+ */
172
+ export type CircuitBreakerState = "closed" | "open" | "half_open";
173
+ /**
174
+ * Status snapshot for a single circuit breaker instance.
175
+ * Maps to CircuitBreaker properties in agent_mesh_router.resilience.circuit_breaker.
176
+ */
177
+ export interface CircuitBreakerStatus {
178
+ /** Human-readable name for this circuit breaker. */
179
+ readonly name: string;
180
+ /** Current state of the circuit breaker. */
181
+ readonly state: CircuitBreakerState;
182
+ /** Consecutive failure count in the current CLOSED window. */
183
+ readonly failure_count: number;
184
+ /** Total calls attempted (not counting rejected calls). */
185
+ readonly total_calls: number;
186
+ /** Total calls rejected because the circuit was open. */
187
+ readonly total_rejected: number;
188
+ /** Number of failures required to open the circuit. */
189
+ readonly failure_threshold: number;
190
+ /** Seconds the circuit stays OPEN before transitioning to HALF_OPEN. */
191
+ readonly recovery_timeout_seconds: number;
192
+ }
193
+ /**
194
+ * Request payload for resolving a conflict between competing agent outputs.
195
+ */
196
+ export interface ResolveConflictRequest {
197
+ /** Identifier of the workflow or task producing conflicting outputs. */
198
+ readonly workflow_id: string;
199
+ /** Competing outputs from different agents, keyed by agent_id. */
200
+ readonly outputs: Readonly<Record<string, unknown>>;
201
+ /** Resolution strategy hint (e.g. "majority", "weighted", "supervisor"). */
202
+ readonly strategy?: string;
203
+ }
204
+ /**
205
+ * Result of conflict resolution between competing agent outputs.
206
+ */
207
+ export interface ConflictResolution {
208
+ /** The workflow that produced conflicting outputs. */
209
+ readonly workflow_id: string;
210
+ /** The resolved output selected or synthesized from competing outputs. */
211
+ readonly resolved_output: Readonly<Record<string, unknown>>;
212
+ /** Agent ID whose output was selected (null for synthesized results). */
213
+ readonly winning_agent_id: string | null;
214
+ /** Resolution strategy that was applied. */
215
+ readonly strategy_applied: string;
216
+ /** Confidence score for the resolution in [0.0, 1.0]. */
217
+ readonly confidence: number;
218
+ }
219
+ /**
220
+ * Configuration for the mesh router.
221
+ * Maps to router configuration options across agent_mesh_router.
222
+ */
223
+ export interface RoutingConfig {
224
+ /** Default workflow pattern to use when not specified. */
225
+ readonly default_pattern: WorkflowPattern;
226
+ /** Default message priority level. */
227
+ readonly default_priority: MessagePriority;
228
+ /** Maximum retries for failed message delivery. */
229
+ readonly max_retries: number;
230
+ /** Whether to enable circuit breaker protection on all routes. */
231
+ readonly circuit_breaker_enabled: boolean;
232
+ /** Seconds before an agent is considered stale (missed heartbeats). */
233
+ readonly heartbeat_timeout_seconds: number;
234
+ }
235
+ /** Standard error payload returned by the agent-mesh-router API. */
236
+ export interface ApiError {
237
+ readonly error: string;
238
+ readonly detail: string;
239
+ }
240
+ /** Result type for all client operations. */
241
+ export type ApiResult<T> = {
242
+ readonly ok: true;
243
+ readonly data: T;
244
+ } | {
245
+ readonly ok: false;
246
+ readonly error: ApiError;
247
+ readonly status: number;
248
+ };
249
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;GAGG;AACH,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,OAAO,GACP,UAAU,GACV,QAAQ,GACR,SAAS,GACT,WAAW,GACX,WAAW,GACX,OAAO,GACP,QAAQ,GACR,KAAK,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAM/E;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;IACnC,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,wDAAwD;IACxD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+BAA+B;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,kCAAkC;IAClC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;IACnC,uBAAuB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,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,4CAA4C;IAC5C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAMD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC;IAC3C,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC;IAC1C,uEAAuE;IACvE,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;CAC5C;AAMD,oEAAoE;AACpE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6CAA6C;AAC7C,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACvC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * TypeScript interfaces for the agent-mesh-router service.
3
+ *
4
+ * Mirrors the Python dataclasses and enums defined in:
5
+ * agent_mesh_router.messages.types
6
+ * agent_mesh_router.workflows.base
7
+ * agent_mesh_router.routing.table
8
+ * agent_mesh_router.fleet.registry
9
+ * agent_mesh_router.resilience.circuit_breaker
10
+ *
11
+ * All interfaces use readonly fields to match Python's frozen dataclasses.
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@aumos/agent-mesh-router",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for the AumOS agent-mesh-router — multi-agent messaging, workflow orchestration, circuit breakers, and topology inspection",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.3.0"
21
+ },
22
+ "keywords": [
23
+ "aumos",
24
+ "agent-mesh-router",
25
+ "mesh",
26
+ "routing",
27
+ "circuit-breaker",
28
+ "workflow",
29
+ "multi-agent",
30
+ "typescript"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/aumos-ai/agent-mesh-router"
35
+ }
36
+ }
package/src/client.ts ADDED
@@ -0,0 +1,256 @@
1
+ /**
2
+ * HTTP client for the agent-mesh-router service API.
3
+ *
4
+ * Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
5
+ * No external dependencies required.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createAgentMeshRouterClient } from "@aumos/agent-mesh-router";
10
+ *
11
+ * const client = createAgentMeshRouterClient({ baseUrl: "http://localhost:8080" });
12
+ *
13
+ * // Send a task message to an agent
14
+ * const result = await client.sendMessage({
15
+ * recipient_id: "summarizer-agent",
16
+ * message_type: "task",
17
+ * payload: { text: "Summarize the quarterly report." },
18
+ * });
19
+ *
20
+ * if (result.ok) {
21
+ * console.log("Message dispatched:", result.data.message_id);
22
+ * }
23
+ *
24
+ * // Execute a sequential workflow
25
+ * const workflow = await client.routeTask({
26
+ * pattern: "sequential",
27
+ * steps: [
28
+ * { agent_id: "reader", action: "extract", params: {}, timeout_seconds: 30, depends_on: [] },
29
+ * { agent_id: "writer", action: "summarize", params: {}, timeout_seconds: 60, depends_on: [] },
30
+ * ],
31
+ * });
32
+ * ```
33
+ */
34
+
35
+ import type {
36
+ AgentRoute,
37
+ ApiError,
38
+ ApiResult,
39
+ CircuitBreakerStatus,
40
+ ConflictResolution,
41
+ Message,
42
+ MeshTopology,
43
+ ResolveConflictRequest,
44
+ RouteTaskRequest,
45
+ SendMessageRequest,
46
+ } from "./types.js";
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // Client configuration
50
+ // ---------------------------------------------------------------------------
51
+
52
+ /** Configuration options for the AgentMeshRouterClient. */
53
+ export interface AgentMeshRouterClientConfig {
54
+ /** Base URL of the agent-mesh-router server (e.g. "http://localhost:8080"). */
55
+ readonly baseUrl: string;
56
+ /** Optional request timeout in milliseconds (default: 30000). */
57
+ readonly timeoutMs?: number;
58
+ /** Optional extra HTTP headers sent with every request. */
59
+ readonly headers?: Readonly<Record<string, string>>;
60
+ }
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Internal helpers
64
+ // ---------------------------------------------------------------------------
65
+
66
+ async function fetchJson<T>(
67
+ url: string,
68
+ init: RequestInit,
69
+ timeoutMs: number,
70
+ ): Promise<ApiResult<T>> {
71
+ const controller = new AbortController();
72
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
73
+
74
+ try {
75
+ const response = await fetch(url, { ...init, signal: controller.signal });
76
+ clearTimeout(timeoutId);
77
+
78
+ const body = await response.json() as unknown;
79
+
80
+ if (!response.ok) {
81
+ const errorBody = body as Partial<ApiError>;
82
+ return {
83
+ ok: false,
84
+ error: {
85
+ error: errorBody.error ?? "Unknown error",
86
+ detail: errorBody.detail ?? "",
87
+ },
88
+ status: response.status,
89
+ };
90
+ }
91
+
92
+ return { ok: true, data: body as T };
93
+ } catch (err: unknown) {
94
+ clearTimeout(timeoutId);
95
+ const message = err instanceof Error ? err.message : String(err);
96
+ return {
97
+ ok: false,
98
+ error: { error: "Network error", detail: message },
99
+ status: 0,
100
+ };
101
+ }
102
+ }
103
+
104
+ function buildHeaders(
105
+ extraHeaders: Readonly<Record<string, string>> | undefined,
106
+ ): Record<string, string> {
107
+ return {
108
+ "Content-Type": "application/json",
109
+ Accept: "application/json",
110
+ ...extraHeaders,
111
+ };
112
+ }
113
+
114
+ // ---------------------------------------------------------------------------
115
+ // Client interface
116
+ // ---------------------------------------------------------------------------
117
+
118
+ /** Typed HTTP client for the agent-mesh-router service. */
119
+ export interface AgentMeshRouterClient {
120
+ /**
121
+ * Dispatch a message to a target agent in the mesh.
122
+ *
123
+ * Supports all MessageType variants (task, query, broadcast, etc.).
124
+ * Returns the created Message record including the assigned message_id.
125
+ *
126
+ * @param request - Message dispatch payload with recipient and type.
127
+ * @returns The created Message record with message_id and metadata.
128
+ */
129
+ sendMessage(request: SendMessageRequest): Promise<ApiResult<Message>>;
130
+
131
+ /**
132
+ * Execute a multi-step workflow through the agent mesh.
133
+ *
134
+ * The workflow pattern controls how steps are coordinated:
135
+ * - sequential: steps run one after another in order
136
+ * - parallel: all steps run concurrently with fan-out/fan-in
137
+ * - hierarchical: a supervisor agent delegates to sub-agents
138
+ * - competitive: all steps race; first result wins
139
+ * - consensus: results are collected and voted upon
140
+ *
141
+ * @param request - Workflow execution request with pattern and steps.
142
+ * @returns AgentRoute with per-step results, status, and total duration.
143
+ */
144
+ routeTask(request: RouteTaskRequest): Promise<ApiResult<AgentRoute>>;
145
+
146
+ /**
147
+ * Retrieve the current mesh topology including all registered agent nodes.
148
+ *
149
+ * @returns MeshTopology snapshot with nodes, counts, and capture timestamp.
150
+ */
151
+ getTopology(): Promise<ApiResult<MeshTopology>>;
152
+
153
+ /**
154
+ * Retrieve the status of a named circuit breaker.
155
+ *
156
+ * Circuit breakers protect mesh routes from cascading failures. This
157
+ * endpoint returns the current state (closed/open/half_open) and
158
+ * cumulative call/rejection counts.
159
+ *
160
+ * @param circuitName - The human-readable circuit breaker name.
161
+ * @returns CircuitBreakerStatus snapshot with state and counters.
162
+ */
163
+ getCircuitBreakerStatus(circuitName: string): Promise<ApiResult<CircuitBreakerStatus>>;
164
+
165
+ /**
166
+ * Resolve a conflict between competing agent outputs.
167
+ *
168
+ * Used after competitive or consensus workflows produce disagreeing results.
169
+ * The configured resolution strategy (majority, weighted, supervisor, etc.)
170
+ * determines how a winner is selected or synthesized.
171
+ *
172
+ * @param request - Conflict resolution request with competing outputs.
173
+ * @returns ConflictResolution with the resolved output and winning agent.
174
+ */
175
+ resolveConflict(
176
+ request: ResolveConflictRequest,
177
+ ): Promise<ApiResult<ConflictResolution>>;
178
+ }
179
+
180
+ // ---------------------------------------------------------------------------
181
+ // Client factory
182
+ // ---------------------------------------------------------------------------
183
+
184
+ /**
185
+ * Create a typed HTTP client for the agent-mesh-router service.
186
+ *
187
+ * @param config - Client configuration including base URL.
188
+ * @returns An AgentMeshRouterClient instance.
189
+ */
190
+ export function createAgentMeshRouterClient(
191
+ config: AgentMeshRouterClientConfig,
192
+ ): AgentMeshRouterClient {
193
+ const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
194
+ const baseHeaders = buildHeaders(extraHeaders);
195
+
196
+ return {
197
+ async sendMessage(
198
+ request: SendMessageRequest,
199
+ ): Promise<ApiResult<Message>> {
200
+ return fetchJson<Message>(
201
+ `${baseUrl}/messages`,
202
+ {
203
+ method: "POST",
204
+ headers: baseHeaders,
205
+ body: JSON.stringify(request),
206
+ },
207
+ timeoutMs,
208
+ );
209
+ },
210
+
211
+ async routeTask(request: RouteTaskRequest): Promise<ApiResult<AgentRoute>> {
212
+ return fetchJson<AgentRoute>(
213
+ `${baseUrl}/workflows`,
214
+ {
215
+ method: "POST",
216
+ headers: baseHeaders,
217
+ body: JSON.stringify(request),
218
+ },
219
+ timeoutMs,
220
+ );
221
+ },
222
+
223
+ async getTopology(): Promise<ApiResult<MeshTopology>> {
224
+ return fetchJson<MeshTopology>(
225
+ `${baseUrl}/topology`,
226
+ { method: "GET", headers: baseHeaders },
227
+ timeoutMs,
228
+ );
229
+ },
230
+
231
+ async getCircuitBreakerStatus(
232
+ circuitName: string,
233
+ ): Promise<ApiResult<CircuitBreakerStatus>> {
234
+ return fetchJson<CircuitBreakerStatus>(
235
+ `${baseUrl}/circuit-breakers/${encodeURIComponent(circuitName)}`,
236
+ { method: "GET", headers: baseHeaders },
237
+ timeoutMs,
238
+ );
239
+ },
240
+
241
+ async resolveConflict(
242
+ request: ResolveConflictRequest,
243
+ ): Promise<ApiResult<ConflictResolution>> {
244
+ return fetchJson<ConflictResolution>(
245
+ `${baseUrl}/conflicts/resolve`,
246
+ {
247
+ method: "POST",
248
+ headers: baseHeaders,
249
+ body: JSON.stringify(request),
250
+ },
251
+ timeoutMs,
252
+ );
253
+ },
254
+ };
255
+ }
256
+
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @aumos/agent-mesh-router
3
+ *
4
+ * TypeScript client for the AumOS agent-mesh-router service.
5
+ * Provides HTTP client and type definitions for multi-agent messaging,
6
+ * workflow orchestration, circuit breaker inspection, and conflict resolution.
7
+ */
8
+
9
+ // Client and configuration
10
+ export type { AgentMeshRouterClient, AgentMeshRouterClientConfig } from "./client.js";
11
+ export { createAgentMeshRouterClient } from "./client.js";
12
+
13
+ // Core types
14
+ export type {
15
+ MessageType,
16
+ MessagePriority,
17
+ Message,
18
+ SendMessageRequest,
19
+ WorkflowPattern,
20
+ WorkflowStep,
21
+ StepResult,
22
+ WorkflowStatus,
23
+ AgentRoute,
24
+ RouteTaskRequest,
25
+ AgentStatus,
26
+ MeshNode,
27
+ MeshTopology,
28
+ CircuitBreakerState,
29
+ CircuitBreakerStatus,
30
+ ResolveConflictRequest,
31
+ ConflictResolution,
32
+ RoutingConfig,
33
+ ApiError,
34
+ ApiResult,
35
+ } from "./types.js";
package/src/types.ts ADDED
@@ -0,0 +1,318 @@
1
+ /**
2
+ * TypeScript interfaces for the agent-mesh-router service.
3
+ *
4
+ * Mirrors the Python dataclasses and enums defined in:
5
+ * agent_mesh_router.messages.types
6
+ * agent_mesh_router.workflows.base
7
+ * agent_mesh_router.routing.table
8
+ * agent_mesh_router.fleet.registry
9
+ * agent_mesh_router.resilience.circuit_breaker
10
+ *
11
+ * All interfaces use readonly fields to match Python's frozen dataclasses.
12
+ */
13
+
14
+ // ---------------------------------------------------------------------------
15
+ // Message types and priority
16
+ // ---------------------------------------------------------------------------
17
+
18
+ /**
19
+ * Discriminator for inter-agent message semantics.
20
+ * Maps to MessageType enum in agent_mesh_router.messages.types.
21
+ */
22
+ export type MessageType =
23
+ | "task"
24
+ | "query"
25
+ | "response"
26
+ | "result"
27
+ | "handoff"
28
+ | "broadcast"
29
+ | "heartbeat"
30
+ | "error"
31
+ | "cancel"
32
+ | "ack";
33
+
34
+ /**
35
+ * Message priority levels compatible with asyncio.PriorityQueue ordering.
36
+ * Lower numeric values are processed first.
37
+ * Maps to Priority enum in agent_mesh_router.messages.types.
38
+ */
39
+ export type MessagePriority = "CRITICAL" | "HIGH" | "NORMAL" | "LOW" | "BATCH";
40
+
41
+ // ---------------------------------------------------------------------------
42
+ // Message
43
+ // ---------------------------------------------------------------------------
44
+
45
+ /**
46
+ * An inter-agent message routed through the mesh.
47
+ * Encompasses all MessageType variants.
48
+ */
49
+ export interface Message {
50
+ /** Unique message identifier (UUID4). */
51
+ readonly message_id: string;
52
+ /** Discriminator for message semantics. */
53
+ readonly message_type: MessageType;
54
+ /** Agent identifier of the sender. */
55
+ readonly sender_id: string;
56
+ /** Agent identifier of the intended recipient (empty for broadcasts). */
57
+ readonly recipient_id: string;
58
+ /** Message payload — arbitrary key-value pairs. */
59
+ readonly payload: Readonly<Record<string, unknown>>;
60
+ /** Priority level controlling queue ordering. */
61
+ readonly priority: MessagePriority;
62
+ /** ISO-8601 UTC timestamp when the message was created. */
63
+ readonly created_at: string;
64
+ /** Optional correlation ID linking related messages (e.g. request/response). */
65
+ readonly correlation_id?: string;
66
+ /** Optional topic string used for broadcast fan-out. */
67
+ readonly topic?: string;
68
+ }
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // SendMessageRequest
72
+ // ---------------------------------------------------------------------------
73
+
74
+ /**
75
+ * Request payload for dispatching a message into the mesh.
76
+ */
77
+ export interface SendMessageRequest {
78
+ /** Target agent identifier. */
79
+ readonly recipient_id: string;
80
+ /** Message type discriminator. */
81
+ readonly message_type: MessageType;
82
+ /** Message payload. */
83
+ readonly payload: Readonly<Record<string, unknown>>;
84
+ /** Priority level (default "NORMAL"). */
85
+ readonly priority?: MessagePriority;
86
+ /** Optional correlation ID for request/response linking. */
87
+ readonly correlation_id?: string;
88
+ }
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // Workflow pattern and steps
92
+ // ---------------------------------------------------------------------------
93
+
94
+ /**
95
+ * Workflow coordination pattern.
96
+ * Maps to WorkflowExecutor subclass names in agent_mesh_router.workflows.
97
+ */
98
+ export type WorkflowPattern =
99
+ | "sequential"
100
+ | "parallel"
101
+ | "hierarchical"
102
+ | "competitive"
103
+ | "consensus";
104
+
105
+ /**
106
+ * A single step within a workflow.
107
+ * Maps to WorkflowStep dataclass in agent_mesh_router.workflows.base.
108
+ */
109
+ export interface WorkflowStep {
110
+ /** Unique identifier for this step (UUID4). */
111
+ readonly step_id: string;
112
+ /** Agent responsible for executing this step. */
113
+ readonly agent_id: string;
114
+ /** Action or operation name (e.g. "summarize", "translate"). */
115
+ readonly action: string;
116
+ /** Parameters passed to the agent for this action. */
117
+ readonly params: Readonly<Record<string, unknown>>;
118
+ /** Maximum seconds allowed for this step (null = no per-step timeout). */
119
+ readonly timeout_seconds: number | null;
120
+ /** step_id values that must complete before this step may execute. */
121
+ readonly depends_on: readonly string[];
122
+ }
123
+
124
+ /**
125
+ * Outcome of executing a single WorkflowStep.
126
+ * Maps to StepResult dataclass in agent_mesh_router.workflows.base.
127
+ */
128
+ export interface StepResult {
129
+ /** Matches the WorkflowStep.step_id that produced this result. */
130
+ readonly step_id: string;
131
+ /** True when the step completed without error. */
132
+ readonly success: boolean;
133
+ /** Data returned by the agent for this step (null on failure). */
134
+ readonly output: Readonly<Record<string, unknown>> | null;
135
+ /** Wall-clock milliseconds taken to execute this step. */
136
+ readonly duration_ms: number;
137
+ /** Error description when success is false (null on success). */
138
+ readonly error: string | null;
139
+ }
140
+
141
+ /**
142
+ * Overall status of a workflow execution.
143
+ * Maps to WorkflowStatus enum in agent_mesh_router.workflows.base.
144
+ */
145
+ export type WorkflowStatus = "success" | "partial" | "failed" | "cancelled";
146
+
147
+ /**
148
+ * Aggregate outcome of a complete workflow execution.
149
+ * Maps to WorkflowResult dataclass in agent_mesh_router.workflows.base.
150
+ */
151
+ export interface AgentRoute {
152
+ /** Unique identifier for this workflow run (UUID4). */
153
+ readonly workflow_id: string;
154
+ /** Ordered list of individual step outcomes. */
155
+ readonly step_results: readonly StepResult[];
156
+ /** Overall workflow status. */
157
+ readonly status: WorkflowStatus;
158
+ /** Total wall-clock milliseconds from first step start to last step end. */
159
+ readonly duration_ms: number;
160
+ }
161
+
162
+ // ---------------------------------------------------------------------------
163
+ // RouteTaskRequest
164
+ // ---------------------------------------------------------------------------
165
+
166
+ /**
167
+ * Request payload for executing a multi-step workflow through the mesh.
168
+ */
169
+ export interface RouteTaskRequest {
170
+ /** Coordination pattern for this workflow. */
171
+ readonly pattern: WorkflowPattern;
172
+ /** Ordered list of steps to execute. */
173
+ readonly steps: readonly Omit<WorkflowStep, "step_id">[];
174
+ /** Optional workflow-level timeout in seconds. */
175
+ readonly timeout_seconds?: number;
176
+ }
177
+
178
+ // ---------------------------------------------------------------------------
179
+ // Mesh topology
180
+ // ---------------------------------------------------------------------------
181
+
182
+ /**
183
+ * Lifecycle status of an agent node in the fleet.
184
+ * Maps to AgentStatus enum in agent_mesh_router.fleet.registry.
185
+ */
186
+ export type AgentStatus = "HEALTHY" | "UNHEALTHY" | "DEGRADED" | "STARTING" | "STOPPING";
187
+
188
+ /**
189
+ * A single agent node in the fleet registry.
190
+ * Maps to AgentNode dataclass in agent_mesh_router.fleet.registry.
191
+ */
192
+ export interface MeshNode {
193
+ /** Unique agent identifier. */
194
+ readonly agent_id: string;
195
+ /** Capability strings this agent exposes. */
196
+ readonly capabilities: readonly string[];
197
+ /** Current lifecycle status. */
198
+ readonly status: AgentStatus;
199
+ /** Normalized load in [0.0, 1.0]; 0.0 = idle, 1.0 = fully loaded. */
200
+ readonly load_score: number;
201
+ /** Unix epoch seconds of the most recent heartbeat received. */
202
+ readonly last_heartbeat: number;
203
+ /** Free-form key-value metadata (region, version, model, etc.). */
204
+ readonly metadata: Readonly<Record<string, string>>;
205
+ }
206
+
207
+ /**
208
+ * Snapshot of the full mesh topology returned by getTopology().
209
+ */
210
+ export interface MeshTopology {
211
+ /** All currently registered agent nodes. */
212
+ readonly nodes: readonly MeshNode[];
213
+ /** Total number of registered nodes. */
214
+ readonly total_count: number;
215
+ /** Number of nodes with HEALTHY status. */
216
+ readonly healthy_count: number;
217
+ /** ISO-8601 UTC timestamp when this snapshot was captured. */
218
+ readonly captured_at: string;
219
+ }
220
+
221
+ // ---------------------------------------------------------------------------
222
+ // Circuit breaker
223
+ // ---------------------------------------------------------------------------
224
+
225
+ /**
226
+ * Possible states of a circuit breaker.
227
+ * Maps to CircuitState enum in agent_mesh_router.resilience.circuit_breaker.
228
+ */
229
+ export type CircuitBreakerState = "closed" | "open" | "half_open";
230
+
231
+ /**
232
+ * Status snapshot for a single circuit breaker instance.
233
+ * Maps to CircuitBreaker properties in agent_mesh_router.resilience.circuit_breaker.
234
+ */
235
+ export interface CircuitBreakerStatus {
236
+ /** Human-readable name for this circuit breaker. */
237
+ readonly name: string;
238
+ /** Current state of the circuit breaker. */
239
+ readonly state: CircuitBreakerState;
240
+ /** Consecutive failure count in the current CLOSED window. */
241
+ readonly failure_count: number;
242
+ /** Total calls attempted (not counting rejected calls). */
243
+ readonly total_calls: number;
244
+ /** Total calls rejected because the circuit was open. */
245
+ readonly total_rejected: number;
246
+ /** Number of failures required to open the circuit. */
247
+ readonly failure_threshold: number;
248
+ /** Seconds the circuit stays OPEN before transitioning to HALF_OPEN. */
249
+ readonly recovery_timeout_seconds: number;
250
+ }
251
+
252
+ // ---------------------------------------------------------------------------
253
+ // Conflict resolution
254
+ // ---------------------------------------------------------------------------
255
+
256
+ /**
257
+ * Request payload for resolving a conflict between competing agent outputs.
258
+ */
259
+ export interface ResolveConflictRequest {
260
+ /** Identifier of the workflow or task producing conflicting outputs. */
261
+ readonly workflow_id: string;
262
+ /** Competing outputs from different agents, keyed by agent_id. */
263
+ readonly outputs: Readonly<Record<string, unknown>>;
264
+ /** Resolution strategy hint (e.g. "majority", "weighted", "supervisor"). */
265
+ readonly strategy?: string;
266
+ }
267
+
268
+ /**
269
+ * Result of conflict resolution between competing agent outputs.
270
+ */
271
+ export interface ConflictResolution {
272
+ /** The workflow that produced conflicting outputs. */
273
+ readonly workflow_id: string;
274
+ /** The resolved output selected or synthesized from competing outputs. */
275
+ readonly resolved_output: Readonly<Record<string, unknown>>;
276
+ /** Agent ID whose output was selected (null for synthesized results). */
277
+ readonly winning_agent_id: string | null;
278
+ /** Resolution strategy that was applied. */
279
+ readonly strategy_applied: string;
280
+ /** Confidence score for the resolution in [0.0, 1.0]. */
281
+ readonly confidence: number;
282
+ }
283
+
284
+ // ---------------------------------------------------------------------------
285
+ // Routing configuration
286
+ // ---------------------------------------------------------------------------
287
+
288
+ /**
289
+ * Configuration for the mesh router.
290
+ * Maps to router configuration options across agent_mesh_router.
291
+ */
292
+ export interface RoutingConfig {
293
+ /** Default workflow pattern to use when not specified. */
294
+ readonly default_pattern: WorkflowPattern;
295
+ /** Default message priority level. */
296
+ readonly default_priority: MessagePriority;
297
+ /** Maximum retries for failed message delivery. */
298
+ readonly max_retries: number;
299
+ /** Whether to enable circuit breaker protection on all routes. */
300
+ readonly circuit_breaker_enabled: boolean;
301
+ /** Seconds before an agent is considered stale (missed heartbeats). */
302
+ readonly heartbeat_timeout_seconds: number;
303
+ }
304
+
305
+ // ---------------------------------------------------------------------------
306
+ // API result wrapper (shared pattern)
307
+ // ---------------------------------------------------------------------------
308
+
309
+ /** Standard error payload returned by the agent-mesh-router API. */
310
+ export interface ApiError {
311
+ readonly error: string;
312
+ readonly detail: string;
313
+ }
314
+
315
+ /** Result type for all client operations. */
316
+ export type ApiResult<T> =
317
+ | { readonly ok: true; readonly data: T }
318
+ | { readonly ok: false; readonly error: ApiError; readonly status: number };
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2020", "DOM"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "strictNullChecks": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noImplicitReturns": true,
18
+ "exactOptionalPropertyTypes": true,
19
+ "forceConsistentCasingInFileNames": true,
20
+ "esModuleInterop": true,
21
+ "skipLibCheck": true
22
+ },
23
+ "include": ["src/**/*"],
24
+ "exclude": ["node_modules", "dist"]
25
+ }