@sw4rm/js-sdk 0.3.0 → 0.5.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.
- package/README.md +13 -0
- package/dist/cjs/index.cjs +3576 -342
- package/dist/esm/index.js +3497 -336
- package/dist/types/agentConfig.d.ts +245 -0
- package/dist/types/audit.d.ts +214 -0
- package/dist/types/clients/handoff.d.ts +188 -0
- package/dist/types/clients/negotiationRoom.d.ts +423 -0
- package/dist/types/clients/negotiationRoomStore.d.ts +155 -0
- package/dist/types/clients/workflow.d.ts +316 -0
- package/dist/types/constants/index.d.ts +100 -0
- package/dist/types/index.d.ts +15 -4
- package/dist/types/internal/baseClient.d.ts +7 -1
- package/dist/types/internal/envelope.d.ts +16 -0
- package/dist/types/internal/errorMapping.d.ts +114 -0
- package/dist/types/internal/worktreeState.d.ts +60 -0
- package/dist/types/persistentActivityBuffer.d.ts +94 -0
- package/dist/types/runtime/agentState.d.ts +205 -0
- package/dist/types/runtime/policyStore.d.ts +391 -0
- package/dist/types/runtime/voting.d.ts +208 -0
- package/package.json +4 -2
- package/protos/activity.proto +24 -0
- package/protos/common.proto +134 -0
- package/protos/connector.proto +29 -0
- package/protos/handoff.proto +63 -0
- package/protos/hitl.proto +23 -0
- package/protos/logging.proto +20 -0
- package/protos/negotiation.proto +57 -0
- package/protos/negotiation_room.proto +220 -0
- package/protos/policy.proto +55 -0
- package/protos/reasoning.proto +41 -0
- package/protos/registry.proto +36 -0
- package/protos/router.proto +16 -0
- package/protos/scheduler.proto +52 -0
- package/protos/scheduler_policy.proto +36 -0
- package/protos/tool.proto +47 -0
- package/protos/workflow.proto +116 -0
- package/protos/worktree.proto +33 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow client for SW4RM.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the WorkflowClient for managing DAG-based workflow
|
|
5
|
+
* orchestration. Workflows enable:
|
|
6
|
+
* - Multi-step task coordination
|
|
7
|
+
* - Dependency-based execution ordering
|
|
8
|
+
* - Node-level state tracking
|
|
9
|
+
* - Context passing between nodes
|
|
10
|
+
*
|
|
11
|
+
* Based on workflow.proto definitions.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Status of a workflow node.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum NodeStatus {
|
|
17
|
+
NODE_STATUS_UNSPECIFIED = 0,
|
|
18
|
+
/** Node waiting for dependencies */
|
|
19
|
+
PENDING = 1,
|
|
20
|
+
/** Node ready to execute */
|
|
21
|
+
READY = 2,
|
|
22
|
+
/** Node currently executing */
|
|
23
|
+
RUNNING = 3,
|
|
24
|
+
/** Node finished successfully */
|
|
25
|
+
COMPLETED = 4,
|
|
26
|
+
/** Node encountered an error */
|
|
27
|
+
FAILED = 5,
|
|
28
|
+
/** Node skipped due to conditional logic */
|
|
29
|
+
SKIPPED = 6
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Type of trigger for a workflow node.
|
|
33
|
+
*/
|
|
34
|
+
export declare enum TriggerType {
|
|
35
|
+
TRIGGER_TYPE_UNSPECIFIED = 0,
|
|
36
|
+
/** Triggered by specific events */
|
|
37
|
+
EVENT = 1,
|
|
38
|
+
/** Triggered on a schedule (cron-like) */
|
|
39
|
+
SCHEDULE = 2,
|
|
40
|
+
/** Triggered by explicit user action */
|
|
41
|
+
MANUAL = 3,
|
|
42
|
+
/** Triggered by dependency completion */
|
|
43
|
+
DEPENDENCY = 4
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Status of a workflow instance.
|
|
47
|
+
*/
|
|
48
|
+
export declare enum WorkflowStatus {
|
|
49
|
+
WORKFLOW_STATUS_UNSPECIFIED = 0,
|
|
50
|
+
/** Workflow has been created but not started */
|
|
51
|
+
CREATED = 1,
|
|
52
|
+
/** Workflow is currently running */
|
|
53
|
+
RUNNING = 2,
|
|
54
|
+
/** Workflow completed successfully */
|
|
55
|
+
COMPLETED = 3,
|
|
56
|
+
/** Workflow failed with error */
|
|
57
|
+
FAILED = 4,
|
|
58
|
+
/** Workflow was cancelled */
|
|
59
|
+
CANCELLED = 5,
|
|
60
|
+
/** Workflow is paused */
|
|
61
|
+
PAUSED = 6
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A node in a workflow definition.
|
|
65
|
+
*
|
|
66
|
+
* Represents a single step in the workflow DAG with its dependencies,
|
|
67
|
+
* trigger conditions, and input/output mappings.
|
|
68
|
+
*/
|
|
69
|
+
export interface WorkflowNode {
|
|
70
|
+
/** Unique identifier for this node */
|
|
71
|
+
nodeId: string;
|
|
72
|
+
/** Identifier of the agent executing this node */
|
|
73
|
+
agentId: string;
|
|
74
|
+
/** Set of node_ids that must complete before this node runs */
|
|
75
|
+
dependencies: string[];
|
|
76
|
+
/** How this node is triggered */
|
|
77
|
+
triggerType: TriggerType;
|
|
78
|
+
/** Maps workflow state keys to node input parameters */
|
|
79
|
+
inputMapping: Record<string, string>;
|
|
80
|
+
/** Maps node output keys to workflow state keys */
|
|
81
|
+
outputMapping: Record<string, string>;
|
|
82
|
+
/** Additional node configuration and context */
|
|
83
|
+
metadata: Record<string, string>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A workflow definition.
|
|
87
|
+
*
|
|
88
|
+
* Describes a complete workflow as a DAG of nodes with their
|
|
89
|
+
* dependencies and configuration.
|
|
90
|
+
*/
|
|
91
|
+
export interface WorkflowDefinition {
|
|
92
|
+
/** Unique identifier for this workflow */
|
|
93
|
+
workflowId: string;
|
|
94
|
+
/** Map of node_id to WorkflowNode */
|
|
95
|
+
nodes: Record<string, WorkflowNode>;
|
|
96
|
+
/** When the workflow was created (ISO-8601 string) */
|
|
97
|
+
createdAt?: string;
|
|
98
|
+
/** Additional workflow-level configuration */
|
|
99
|
+
metadata: Record<string, string>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* State of a single node during execution.
|
|
103
|
+
*/
|
|
104
|
+
export interface NodeState {
|
|
105
|
+
/** The node this state belongs to */
|
|
106
|
+
nodeId: string;
|
|
107
|
+
/** Current execution status */
|
|
108
|
+
status: NodeStatus;
|
|
109
|
+
/** When node execution started (ISO-8601 string) */
|
|
110
|
+
startedAt?: string;
|
|
111
|
+
/** When node execution completed (ISO-8601 string) */
|
|
112
|
+
completedAt?: string;
|
|
113
|
+
/** Output data from node execution (JSON string) */
|
|
114
|
+
output?: string;
|
|
115
|
+
/** Error information if node failed */
|
|
116
|
+
error?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A running instance of a workflow.
|
|
120
|
+
*
|
|
121
|
+
* Tracks the execution state of all nodes and the shared workflow data.
|
|
122
|
+
*/
|
|
123
|
+
export interface WorkflowInstance {
|
|
124
|
+
/** Identifier of this workflow instance */
|
|
125
|
+
instanceId: string;
|
|
126
|
+
/** Identifier of the workflow definition */
|
|
127
|
+
workflowId: string;
|
|
128
|
+
/** Current status of the workflow */
|
|
129
|
+
status: WorkflowStatus;
|
|
130
|
+
/** Map of node_id to NodeState for tracking execution */
|
|
131
|
+
nodeStates: Record<string, NodeState>;
|
|
132
|
+
/** Shared workflow data (JSON string) */
|
|
133
|
+
workflowData: string;
|
|
134
|
+
/** When the workflow execution started (ISO-8601 string) */
|
|
135
|
+
startedAt?: string;
|
|
136
|
+
/** When the workflow execution completed (ISO-8601 string) */
|
|
137
|
+
completedAt?: string;
|
|
138
|
+
/** Additional runtime metadata */
|
|
139
|
+
metadata: Record<string, string>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Error thrown when a workflow operation fails validation.
|
|
143
|
+
*/
|
|
144
|
+
export declare class WorkflowValidationError extends Error {
|
|
145
|
+
constructor(message: string);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Error thrown when a workflow contains a cycle.
|
|
149
|
+
*/
|
|
150
|
+
export declare class WorkflowCycleError extends Error {
|
|
151
|
+
constructor(message: string);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Client for managing workflow orchestration.
|
|
155
|
+
*
|
|
156
|
+
* Enables creation and execution of DAG-based workflows that coordinate
|
|
157
|
+
* multiple agents. This is an in-memory implementation for Phase 2;
|
|
158
|
+
* future phases will integrate with gRPC services.
|
|
159
|
+
*/
|
|
160
|
+
export declare class WorkflowClient {
|
|
161
|
+
private definitions;
|
|
162
|
+
private instances;
|
|
163
|
+
private instancesByWorkflow;
|
|
164
|
+
/**
|
|
165
|
+
* Create a new workflow from a definition.
|
|
166
|
+
*
|
|
167
|
+
* Validates the workflow definition and stores it for later execution.
|
|
168
|
+
*
|
|
169
|
+
* @param definition - The workflow definition to create
|
|
170
|
+
* @returns The workflow_id of the created workflow
|
|
171
|
+
* @throws WorkflowValidationError if the definition is invalid
|
|
172
|
+
* @throws WorkflowCycleError if the workflow contains a cycle
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const client = new WorkflowClient();
|
|
177
|
+
* const definition: WorkflowDefinition = {
|
|
178
|
+
* workflowId: "review-workflow",
|
|
179
|
+
* nodes: {
|
|
180
|
+
* "produce": {
|
|
181
|
+
* nodeId: "produce",
|
|
182
|
+
* agentId: "producer-agent",
|
|
183
|
+
* dependencies: [],
|
|
184
|
+
* triggerType: TriggerType.MANUAL,
|
|
185
|
+
* inputMapping: {},
|
|
186
|
+
* outputMapping: { "artifact": "produced_artifact" },
|
|
187
|
+
* metadata: {}
|
|
188
|
+
* },
|
|
189
|
+
* "review": {
|
|
190
|
+
* nodeId: "review",
|
|
191
|
+
* agentId: "critic-agent",
|
|
192
|
+
* dependencies: ["produce"],
|
|
193
|
+
* triggerType: TriggerType.DEPENDENCY,
|
|
194
|
+
* inputMapping: { "artifact": "produced_artifact" },
|
|
195
|
+
* outputMapping: { "result": "review_result" },
|
|
196
|
+
* metadata: {}
|
|
197
|
+
* }
|
|
198
|
+
* },
|
|
199
|
+
* metadata: {}
|
|
200
|
+
* };
|
|
201
|
+
* const workflowId = await client.createWorkflow(definition);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
createWorkflow(definition: WorkflowDefinition): Promise<string>;
|
|
205
|
+
/**
|
|
206
|
+
* Start a new instance of a workflow.
|
|
207
|
+
*
|
|
208
|
+
* Creates a new workflow instance and initializes all nodes to their
|
|
209
|
+
* starting states based on dependencies.
|
|
210
|
+
*
|
|
211
|
+
* @param workflowId - The ID of the workflow to start
|
|
212
|
+
* @param initialData - Optional initial workflow data (JSON string)
|
|
213
|
+
* @param metadata - Optional runtime metadata
|
|
214
|
+
* @returns The created workflow instance
|
|
215
|
+
* @throws WorkflowValidationError if the workflow does not exist
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const instance = await client.startWorkflow("review-workflow");
|
|
220
|
+
* console.log(instance.status); // WorkflowStatus.RUNNING
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
startWorkflow(workflowId: string, initialData?: string, metadata?: Record<string, string>): Promise<WorkflowInstance>;
|
|
224
|
+
/**
|
|
225
|
+
* Get the current status of a workflow instance.
|
|
226
|
+
*
|
|
227
|
+
* @param instanceId - The ID of the workflow instance
|
|
228
|
+
* @returns The workflow instance with current state
|
|
229
|
+
* @throws WorkflowValidationError if the instance does not exist
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const instance = await client.getWorkflowStatus("wf-123-abc");
|
|
234
|
+
* console.log(instance.status);
|
|
235
|
+
* for (const [nodeId, state] of Object.entries(instance.nodeStates)) {
|
|
236
|
+
* console.log(`${nodeId}: ${NodeStatus[state.status]}`);
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
getWorkflowStatus(instanceId: string): Promise<WorkflowInstance>;
|
|
241
|
+
/**
|
|
242
|
+
* Cancel a running workflow instance.
|
|
243
|
+
*
|
|
244
|
+
* Marks the workflow as cancelled and stops any pending nodes.
|
|
245
|
+
*
|
|
246
|
+
* @param instanceId - The ID of the workflow instance to cancel
|
|
247
|
+
* @throws WorkflowValidationError if the instance does not exist
|
|
248
|
+
* @throws WorkflowValidationError if the workflow is not in a cancellable state
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* await client.cancelWorkflow("wf-123-abc");
|
|
253
|
+
* const instance = await client.getWorkflowStatus("wf-123-abc");
|
|
254
|
+
* console.log(instance.status); // WorkflowStatus.CANCELLED
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
cancelWorkflow(instanceId: string): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Get the workflow definition.
|
|
260
|
+
*
|
|
261
|
+
* @param workflowId - The ID of the workflow
|
|
262
|
+
* @returns The workflow definition if it exists, null otherwise
|
|
263
|
+
*/
|
|
264
|
+
getWorkflowDefinition(workflowId: string): Promise<WorkflowDefinition | null>;
|
|
265
|
+
/**
|
|
266
|
+
* List all instances of a workflow.
|
|
267
|
+
*
|
|
268
|
+
* @param workflowId - The ID of the workflow
|
|
269
|
+
* @returns List of all instances for the workflow
|
|
270
|
+
*/
|
|
271
|
+
listWorkflowInstances(workflowId: string): Promise<WorkflowInstance[]>;
|
|
272
|
+
/**
|
|
273
|
+
* Update the state of a node in a workflow instance.
|
|
274
|
+
*
|
|
275
|
+
* This is an internal method used by node executors to report progress.
|
|
276
|
+
*
|
|
277
|
+
* @param instanceId - The ID of the workflow instance
|
|
278
|
+
* @param nodeId - The ID of the node to update
|
|
279
|
+
* @param status - The new status of the node
|
|
280
|
+
* @param output - Optional output data from the node
|
|
281
|
+
* @param error - Optional error message if the node failed
|
|
282
|
+
* @throws WorkflowValidationError if the instance or node does not exist
|
|
283
|
+
*/
|
|
284
|
+
updateNodeState(instanceId: string, nodeId: string, status: NodeStatus, output?: string, error?: string): Promise<void>;
|
|
285
|
+
/**
|
|
286
|
+
* Update the status of nodes that depend on a completed node.
|
|
287
|
+
*/
|
|
288
|
+
private updateDependentNodes;
|
|
289
|
+
/**
|
|
290
|
+
* Check if a workflow instance is complete and update its status.
|
|
291
|
+
*/
|
|
292
|
+
private checkWorkflowCompletion;
|
|
293
|
+
/**
|
|
294
|
+
* Resume a workflow by marking a node as completed and advancing dependents.
|
|
295
|
+
*
|
|
296
|
+
* Implements the ResumeWorkflow RPC (spec §17.7 MUST). Marks the specified
|
|
297
|
+
* node as COMPLETED, updates workflow data if provided, then transitions
|
|
298
|
+
* dependent nodes from PENDING to READY when all their dependencies are met.
|
|
299
|
+
*
|
|
300
|
+
* @param instanceId - The ID of the workflow instance
|
|
301
|
+
* @param nodeId - The ID of the node to mark as completed
|
|
302
|
+
* @param workflowData - Optional updated workflow data (JSON string)
|
|
303
|
+
* @param metadata - Optional metadata for the resume operation
|
|
304
|
+
* @returns The updated workflow instance
|
|
305
|
+
* @throws WorkflowValidationError if the instance or node does not exist
|
|
306
|
+
*/
|
|
307
|
+
resumeWorkflow(instanceId: string, nodeId: string, workflowData?: string, metadata?: Record<string, string>): Promise<WorkflowInstance>;
|
|
308
|
+
/**
|
|
309
|
+
* Update the shared workflow data.
|
|
310
|
+
*
|
|
311
|
+
* @param instanceId - The ID of the workflow instance
|
|
312
|
+
* @param workflowData - The new workflow data (JSON string)
|
|
313
|
+
* @throws WorkflowValidationError if the instance does not exist
|
|
314
|
+
*/
|
|
315
|
+
updateWorkflowData(instanceId: string, workflowData: string): Promise<void>;
|
|
316
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export { ErrorCode } from '../internal/errorMapping.js';
|
|
2
|
+
export { MessageType } from '../internal/envelope.js';
|
|
3
|
+
/**
|
|
4
|
+
* CommunicationClass constants (spec section 7.3).
|
|
5
|
+
*/
|
|
6
|
+
export declare enum CommunicationClass {
|
|
7
|
+
COMM_CLASS_UNSPECIFIED = 0,
|
|
8
|
+
PRIVILEGED = 1,
|
|
9
|
+
STANDARD = 2,
|
|
10
|
+
BULK = 3
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* DebateIntensity constants (spec section 17).
|
|
14
|
+
*/
|
|
15
|
+
export declare enum DebateIntensity {
|
|
16
|
+
DEBATE_INTENSITY_UNSPECIFIED = 0,
|
|
17
|
+
LOWEST = 1,
|
|
18
|
+
LOW = 2,
|
|
19
|
+
MEDIUM = 3,
|
|
20
|
+
HIGH = 4,
|
|
21
|
+
HIGHEST = 5
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* HitlReasonType constants (spec section 15).
|
|
25
|
+
*/
|
|
26
|
+
export declare enum HitlReasonType {
|
|
27
|
+
HITL_REASON_UNSPECIFIED = 0,
|
|
28
|
+
CONFLICT = 1,
|
|
29
|
+
SECURITY_APPROVAL = 2,
|
|
30
|
+
TASK_ESCALATION = 3,
|
|
31
|
+
MANUAL_OVERRIDE = 4,
|
|
32
|
+
WORKTREE_OVERRIDE = 5,
|
|
33
|
+
DEBATE_DEADLOCK = 6,
|
|
34
|
+
TOOL_PRIVILEGE_ESCALATION = 7,
|
|
35
|
+
CONNECTOR_APPROVAL = 8
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* AgentState constants (spec section 8).
|
|
39
|
+
* Re-exported from agentState.ts for convenience.
|
|
40
|
+
*/
|
|
41
|
+
export { AgentState } from '../runtime/agentState.js';
|
|
42
|
+
/**
|
|
43
|
+
* AckStage constants.
|
|
44
|
+
*/
|
|
45
|
+
export declare enum AckStage {
|
|
46
|
+
ACK_STAGE_UNSPECIFIED = 0,
|
|
47
|
+
RECEIVED = 1,
|
|
48
|
+
READ = 2,
|
|
49
|
+
FULFILLED = 3,
|
|
50
|
+
REJECTED = 4,
|
|
51
|
+
FAILED = 5,
|
|
52
|
+
TIMED_OUT = 6
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* EnvelopeState lifecycle constants.
|
|
56
|
+
*
|
|
57
|
+
* Tracks the lifecycle of an envelope through the system:
|
|
58
|
+
* SENT -> RECEIVED -> READ -> FULFILLED/REJECTED/FAILED/TIMED_OUT
|
|
59
|
+
*/
|
|
60
|
+
export declare enum EnvelopeState {
|
|
61
|
+
ENVELOPE_STATE_UNSPECIFIED = 0,
|
|
62
|
+
SENT = 1,
|
|
63
|
+
RECEIVED = 2,
|
|
64
|
+
READ = 3,
|
|
65
|
+
FULFILLED = 4,
|
|
66
|
+
REJECTED = 5,
|
|
67
|
+
FAILED = 6,
|
|
68
|
+
TIMED_OUT = 7
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* WorktreeState constants (spec section 16).
|
|
72
|
+
*/
|
|
73
|
+
export declare enum WorktreeStateEnum {
|
|
74
|
+
WORKTREE_STATE_UNSPECIFIED = 0,
|
|
75
|
+
UNBOUND = 1,
|
|
76
|
+
BOUND_HOME = 2,
|
|
77
|
+
SWITCH_PENDING = 3,
|
|
78
|
+
BOUND_NON_HOME = 4,
|
|
79
|
+
BIND_FAILED = 5
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Default timeout for acknowledgement in milliseconds.
|
|
83
|
+
*/
|
|
84
|
+
export declare const DEFAULT_ACK_TIMEOUT_MS = 10000;
|
|
85
|
+
/**
|
|
86
|
+
* Deduplication window in seconds.
|
|
87
|
+
*/
|
|
88
|
+
export declare const DEDUP_WINDOW_S = 3600;
|
|
89
|
+
/**
|
|
90
|
+
* Check if an envelope state is terminal (no further transitions expected).
|
|
91
|
+
*
|
|
92
|
+
* Terminal states: FULFILLED, REJECTED, FAILED, TIMED_OUT
|
|
93
|
+
*/
|
|
94
|
+
export declare function isTerminalEnvelopeState(state: EnvelopeState): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Update the state of an envelope object.
|
|
97
|
+
*/
|
|
98
|
+
export declare function updateEnvelopeState<T extends {
|
|
99
|
+
state?: number;
|
|
100
|
+
}>(envelope: T, newState: EnvelopeState): T;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.5.0";
|
|
2
2
|
export * from './clients/router.js';
|
|
3
3
|
export * from './clients/scheduler.js';
|
|
4
4
|
export * from './clients/schedulerPolicy.js';
|
|
@@ -11,27 +11,38 @@ export * from './clients/negotiation.js';
|
|
|
11
11
|
export * from './clients/reasoning.js';
|
|
12
12
|
export * from './clients/connector.js';
|
|
13
13
|
export * from './clients/registry.js';
|
|
14
|
+
export * from './clients/negotiationRoom.js';
|
|
15
|
+
export * from './clients/negotiationRoomStore.js';
|
|
16
|
+
export * from './clients/handoff.js';
|
|
17
|
+
export * from './clients/workflow.js';
|
|
14
18
|
export { buildEnvelope, type EnvelopeBuilt, type EnvelopeInput, nowTimestamp, type Timestamp, } from './internal/envelope.js';
|
|
15
19
|
export * from './internal/errorMapping.js';
|
|
16
|
-
export
|
|
20
|
+
export { ClientOptions, BaseClient, } from './internal/baseClient.js';
|
|
17
21
|
export * from './internal/time.js';
|
|
18
22
|
export * from './internal/interceptors.js';
|
|
19
23
|
export * from './internal/worktreeState.js';
|
|
20
24
|
export * from './internal/worktreePolicy.js';
|
|
21
25
|
export * from './internal/runtime/activityBuffer.js';
|
|
22
|
-
export
|
|
23
|
-
export
|
|
26
|
+
export { AckState, ACKLifecycleManager, } from './internal/runtime/ackLifecycle.js';
|
|
27
|
+
export { EnvelopeLike, MessageProcessor, } from './internal/runtime/messageProcessor.js';
|
|
24
28
|
export * from './runtime/ackHelpers.js';
|
|
25
29
|
export * from './runtime/activitySync.js';
|
|
26
30
|
export * from './runtime/streams.js';
|
|
27
31
|
export * from './runtime/negotiationEvents.js';
|
|
28
32
|
export * from './persistence/persistence.js';
|
|
33
|
+
export * from './runtime/voting.js';
|
|
34
|
+
export * from './runtime/policyStore.js';
|
|
35
|
+
export { AgentState, isValidTransition, getValidTransitions, type AgentLifecycleHooks, AgentStateMachine, } from './runtime/agentState.js';
|
|
29
36
|
export * from './internal/ids.js';
|
|
30
37
|
export * from './internal/idempotency.js';
|
|
31
38
|
export * from './runtime/persistenceAdapter.js';
|
|
32
39
|
export * from './internal/errorMapper.js';
|
|
33
40
|
export * from './internal/ack.js';
|
|
34
41
|
export * from './internal/control.js';
|
|
42
|
+
export { CommunicationClass, DebateIntensity, HitlReasonType, AckStage, EnvelopeState, WorktreeStateEnum, DEFAULT_ACK_TIMEOUT_MS, DEDUP_WINDOW_S, isTerminalEnvelopeState, updateEnvelopeState, MessageType, } from './constants/index.js';
|
|
43
|
+
export * from './audit.js';
|
|
44
|
+
export * from './agentConfig.js';
|
|
45
|
+
export { type EnvelopeRecord, PersistentActivityBuffer, } from './persistentActivityBuffer.js';
|
|
35
46
|
export * from './secrets/types.js';
|
|
36
47
|
export * from './secrets/errors.js';
|
|
37
48
|
export * from './secrets/backend.js';
|
|
@@ -25,9 +25,15 @@ export declare class BaseClient {
|
|
|
25
25
|
protected readonly interceptors: InterceptorChain;
|
|
26
26
|
protected readonly errorMapper: ErrorCodeMapper;
|
|
27
27
|
constructor(opts: ClientOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Resolves the protos directory, checking multiple locations:
|
|
30
|
+
* 1. npm package: ./protos relative to package root
|
|
31
|
+
* 2. Monorepo dev: ../../../../protos relative to this file
|
|
32
|
+
*/
|
|
33
|
+
private resolveProtosDir;
|
|
28
34
|
protected channelCredentials(): grpc.ChannelCredentials;
|
|
29
35
|
protected metadata(base?: grpc.Metadata): grpc.Metadata;
|
|
30
36
|
protected deadlineFromNow(): Date;
|
|
31
37
|
protected getServiceClient<T = any>(fqn: string): T;
|
|
32
|
-
protected withRetryUnary<
|
|
38
|
+
protected withRetryUnary<Res>(fn: () => Promise<Res>, methodName?: string, mdForCtx?: grpc.Metadata): Promise<Res>;
|
|
33
39
|
}
|
|
@@ -30,6 +30,10 @@ export interface EnvelopeInput {
|
|
|
30
30
|
hlc_timestamp?: string;
|
|
31
31
|
ttl_ms?: number;
|
|
32
32
|
timestamp?: Date;
|
|
33
|
+
state?: number;
|
|
34
|
+
effective_policy_id?: string;
|
|
35
|
+
audit_proof?: Uint8Array;
|
|
36
|
+
audit_policy_id?: string;
|
|
33
37
|
}
|
|
34
38
|
export interface EnvelopeBuilt {
|
|
35
39
|
message_id: string;
|
|
@@ -47,7 +51,19 @@ export interface EnvelopeBuilt {
|
|
|
47
51
|
ttl_ms?: number;
|
|
48
52
|
timestamp: Timestamp;
|
|
49
53
|
payload?: Uint8Array;
|
|
54
|
+
state: number;
|
|
55
|
+
effective_policy_id: string;
|
|
56
|
+
audit_proof: Uint8Array;
|
|
57
|
+
audit_policy_id: string;
|
|
50
58
|
}
|
|
51
59
|
export declare function nowTimestamp(date?: Date): Timestamp;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a stub HLC timestamp in the canonical format `HLC:<wall>:<logical>:<node>`.
|
|
62
|
+
*
|
|
63
|
+
* Per spec section 4, the HLC format combines wall-clock time (Unix microseconds),
|
|
64
|
+
* a logical counter (always 0 in this stub), and a node identifier (hostname).
|
|
65
|
+
* Full HLC implementations should increment the logical counter on concurrent
|
|
66
|
+
* events within the same microsecond.
|
|
67
|
+
*/
|
|
52
68
|
export declare function nowHlcStub(date?: Date): string;
|
|
53
69
|
export declare function buildEnvelope(input: EnvelopeInput): EnvelopeBuilt;
|
|
@@ -13,6 +13,8 @@ export declare enum ErrorCode {
|
|
|
13
13
|
PARTIAL_DELIVERY = 11,
|
|
14
14
|
FORCED_PREEMPTION = 12,
|
|
15
15
|
TTL_EXPIRED = 13,
|
|
16
|
+
DUPLICATE_DETECTED = 14,
|
|
17
|
+
ALREADY_IN_PROGRESS = 15,
|
|
16
18
|
INTERNAL_ERROR = 99
|
|
17
19
|
}
|
|
18
20
|
export declare class Sw4rmError extends Error {
|
|
@@ -24,4 +26,116 @@ export declare class Sw4rmError extends Error {
|
|
|
24
26
|
details?: string;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when input validation fails.
|
|
31
|
+
* Default error code: VALIDATION_ERROR
|
|
32
|
+
*/
|
|
33
|
+
export declare class ValidationError extends Sw4rmError {
|
|
34
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
35
|
+
grpcStatus?: number;
|
|
36
|
+
details?: string;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when an operation times out.
|
|
41
|
+
* Default error code: ACK_TIMEOUT
|
|
42
|
+
*/
|
|
43
|
+
export declare class TimeoutError extends Sw4rmError {
|
|
44
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
45
|
+
grpcStatus?: number;
|
|
46
|
+
details?: string;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when an invalid state transition is attempted.
|
|
51
|
+
* Default error code: INTERNAL_ERROR
|
|
52
|
+
*/
|
|
53
|
+
export declare class StateTransitionError extends Sw4rmError {
|
|
54
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
55
|
+
grpcStatus?: number;
|
|
56
|
+
details?: string;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when negotiation fails.
|
|
61
|
+
* Default error code: INTERNAL_ERROR
|
|
62
|
+
*/
|
|
63
|
+
export declare class NegotiationError extends Sw4rmError {
|
|
64
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
65
|
+
grpcStatus?: number;
|
|
66
|
+
details?: string;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Thrown when the activity buffer is full.
|
|
71
|
+
* Default error code: BUFFER_FULL
|
|
72
|
+
*/
|
|
73
|
+
export declare class BufferFullError extends Sw4rmError {
|
|
74
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
75
|
+
grpcStatus?: number;
|
|
76
|
+
details?: string;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when no route to destination exists.
|
|
81
|
+
* Default error code: NO_ROUTE
|
|
82
|
+
*/
|
|
83
|
+
export declare class RouteError extends Sw4rmError {
|
|
84
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
85
|
+
grpcStatus?: number;
|
|
86
|
+
details?: string;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Thrown when permission is denied.
|
|
91
|
+
* Default error code: PERMISSION_DENIED
|
|
92
|
+
*/
|
|
93
|
+
export declare class PermissionError extends Sw4rmError {
|
|
94
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
95
|
+
grpcStatus?: number;
|
|
96
|
+
details?: string;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Thrown when a duplicate request is detected.
|
|
101
|
+
* Default error code: DUPLICATE_DETECTED
|
|
102
|
+
*/
|
|
103
|
+
export declare class DuplicateDetectedError extends Sw4rmError {
|
|
104
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
105
|
+
grpcStatus?: number;
|
|
106
|
+
details?: string;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Thrown when an agent is forcibly preempted by the scheduler.
|
|
111
|
+
* Default error code: FORCED_PREEMPTION
|
|
112
|
+
*/
|
|
113
|
+
export declare class PreemptionError extends Sw4rmError {
|
|
114
|
+
readonly agentId: string;
|
|
115
|
+
readonly reason: string;
|
|
116
|
+
constructor(agentId: string, reason: string, code?: ErrorCode, opts?: {
|
|
117
|
+
grpcStatus?: number;
|
|
118
|
+
details?: string;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Thrown when a worktree operation fails (bind, switch, etc.).
|
|
123
|
+
* Default error code: INTERNAL_ERROR
|
|
124
|
+
*/
|
|
125
|
+
export declare class WorktreeError extends Sw4rmError {
|
|
126
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
127
|
+
grpcStatus?: number;
|
|
128
|
+
details?: string;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Thrown when an action violates a configured policy.
|
|
133
|
+
* Default error code: PERMISSION_DENIED
|
|
134
|
+
*/
|
|
135
|
+
export declare class PolicyViolationError extends Sw4rmError {
|
|
136
|
+
constructor(message: string, code?: ErrorCode, opts?: {
|
|
137
|
+
grpcStatus?: number;
|
|
138
|
+
details?: string;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
27
141
|
export declare function mapGrpcStatusToErrorCode(status: number): ErrorCode;
|