@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.
Files changed (37) hide show
  1. package/README.md +13 -0
  2. package/dist/cjs/index.cjs +3576 -342
  3. package/dist/esm/index.js +3497 -336
  4. package/dist/types/agentConfig.d.ts +245 -0
  5. package/dist/types/audit.d.ts +214 -0
  6. package/dist/types/clients/handoff.d.ts +188 -0
  7. package/dist/types/clients/negotiationRoom.d.ts +423 -0
  8. package/dist/types/clients/negotiationRoomStore.d.ts +155 -0
  9. package/dist/types/clients/workflow.d.ts +316 -0
  10. package/dist/types/constants/index.d.ts +100 -0
  11. package/dist/types/index.d.ts +15 -4
  12. package/dist/types/internal/baseClient.d.ts +7 -1
  13. package/dist/types/internal/envelope.d.ts +16 -0
  14. package/dist/types/internal/errorMapping.d.ts +114 -0
  15. package/dist/types/internal/worktreeState.d.ts +60 -0
  16. package/dist/types/persistentActivityBuffer.d.ts +94 -0
  17. package/dist/types/runtime/agentState.d.ts +205 -0
  18. package/dist/types/runtime/policyStore.d.ts +391 -0
  19. package/dist/types/runtime/voting.d.ts +208 -0
  20. package/package.json +4 -2
  21. package/protos/activity.proto +24 -0
  22. package/protos/common.proto +134 -0
  23. package/protos/connector.proto +29 -0
  24. package/protos/handoff.proto +63 -0
  25. package/protos/hitl.proto +23 -0
  26. package/protos/logging.proto +20 -0
  27. package/protos/negotiation.proto +57 -0
  28. package/protos/negotiation_room.proto +220 -0
  29. package/protos/policy.proto +55 -0
  30. package/protos/reasoning.proto +41 -0
  31. package/protos/registry.proto +36 -0
  32. package/protos/router.proto +16 -0
  33. package/protos/scheduler.proto +52 -0
  34. package/protos/scheduler_policy.proto +36 -0
  35. package/protos/tool.proto +47 -0
  36. package/protos/workflow.proto +116 -0
  37. package/protos/worktree.proto +33 -0
@@ -0,0 +1,391 @@
1
+ /**
2
+ * Policy store for SW4RM.
3
+ *
4
+ * This module provides interfaces and implementations for storing and
5
+ * retrieving negotiation policies. Policies define the rules and thresholds
6
+ * for negotiation workflows.
7
+ *
8
+ * Based on policy.proto definitions.
9
+ */
10
+ /**
11
+ * HITL gate mode for policies.
12
+ */
13
+ export declare enum HitlMode {
14
+ NONE = "None",
15
+ PAUSE_BETWEEN_ROUNDS = "PauseBetweenRounds",
16
+ PAUSE_ON_FINAL_ACCEPT = "PauseOnFinalAccept"
17
+ }
18
+ /**
19
+ * Scoring configuration for policies.
20
+ */
21
+ export interface ScoringConfig {
22
+ /** Whether to require JSON schema validation */
23
+ requireSchemaValid: boolean;
24
+ /** Whether to require examples to pass */
25
+ requireExamplesPass: boolean;
26
+ /** Weight for LLM-based scoring (0-1) */
27
+ llmWeight: number;
28
+ }
29
+ /**
30
+ * A negotiation policy defining rules and thresholds.
31
+ *
32
+ * Policies are used by the scheduler to control negotiation behavior
33
+ * and ensure consistency across negotiations.
34
+ */
35
+ export interface NegotiationPolicy {
36
+ /** Maximum number of negotiation rounds */
37
+ maxRounds: number;
38
+ /** Score threshold for approval (0-1) */
39
+ scoreThreshold: number;
40
+ /** Tolerance for structural differences (0-1) */
41
+ diffTolerance: number;
42
+ /** Timeout per round in milliseconds */
43
+ roundTimeoutMs: number;
44
+ /** Token budget per round */
45
+ tokenBudgetPerRound: number;
46
+ /** Total token budget (0 = unlimited) */
47
+ totalTokenBudget: number;
48
+ /** Maximum oscillations before escalation */
49
+ oscillationLimit: number;
50
+ /** HITL gate mode */
51
+ hitl: HitlMode;
52
+ /** Scoring configuration */
53
+ scoring: ScoringConfig;
54
+ }
55
+ /**
56
+ * Agent preferences for negotiation.
57
+ *
58
+ * Same fields as NegotiationPolicy but advisory; scheduler clamps to guardrails.
59
+ */
60
+ export interface AgentPreferences {
61
+ maxRounds?: number;
62
+ scoreThreshold?: number;
63
+ diffTolerance?: number;
64
+ roundTimeoutMs?: number;
65
+ tokenBudgetPerRound?: number;
66
+ totalTokenBudget?: number;
67
+ oscillationLimit?: number;
68
+ }
69
+ /**
70
+ * Network access policy for execution.
71
+ */
72
+ export type NetworkPolicy = 'none' | 'restricted' | 'full';
73
+ /**
74
+ * Privilege level for execution.
75
+ */
76
+ export type PrivilegeLevel = 'standard' | 'elevated' | 'admin';
77
+ /**
78
+ * Backoff strategy for retries.
79
+ */
80
+ export type BackoffStrategy = 'none' | 'linear' | 'exponential';
81
+ /**
82
+ * Policy governing task execution.
83
+ *
84
+ * Defines constraints and resource limits for executing tasks.
85
+ * Per SPEC_REQUESTS §6.3.
86
+ *
87
+ * Note: Named TaskExecutionPolicy to avoid conflict with tool.ts ExecutionPolicy.
88
+ */
89
+ export interface TaskExecutionPolicy {
90
+ /** Maximum execution time in milliseconds */
91
+ timeoutMs: number;
92
+ /** Maximum number of retry attempts */
93
+ maxRetries: number;
94
+ /** Backoff strategy for retries */
95
+ backoff: BackoffStrategy;
96
+ /** Whether a worktree binding is required for execution */
97
+ worktreeRequired: boolean;
98
+ /** Network access policy */
99
+ networkPolicy: NetworkPolicy;
100
+ /** Required privilege level */
101
+ privilegeLevel: PrivilegeLevel;
102
+ /** CPU time budget in milliseconds */
103
+ budgetCpuMs: number;
104
+ /** Wall clock time budget in milliseconds */
105
+ budgetWallMs: number;
106
+ }
107
+ /**
108
+ * Policy governing escalation behavior.
109
+ *
110
+ * Defines when and how negotiations should be escalated.
111
+ * Per SPEC_REQUESTS §6.3.
112
+ */
113
+ export interface EscalationPolicy {
114
+ /** Whether to automatically escalate when deadlock is detected */
115
+ autoEscalateOnDeadlock: boolean;
116
+ /** Number of rounds without progress before declaring deadlock */
117
+ deadlockRounds: number;
118
+ /** List of valid reasons for escalation */
119
+ escalationReasons: string[];
120
+ /** Default action when escalation is triggered */
121
+ defaultAction: 'retry_same' | 'escalate' | 'fail';
122
+ }
123
+ /**
124
+ * Default execution policy.
125
+ */
126
+ export declare const DEFAULT_EXECUTION_POLICY: TaskExecutionPolicy;
127
+ /**
128
+ * Default escalation policy.
129
+ */
130
+ export declare const DEFAULT_ESCALATION_POLICY: EscalationPolicy;
131
+ /**
132
+ * Effective policy after applying agent preferences and scheduler guardrails.
133
+ *
134
+ * Combines negotiation, execution, and escalation policies as per SPEC_REQUESTS §6.3.
135
+ */
136
+ export interface EffectivePolicy {
137
+ /** Unique identifier for this effective policy */
138
+ policyId: string;
139
+ /** Version string for the policy (timestamp_uuid format) */
140
+ version: string;
141
+ /** The derived authoritative negotiation policy */
142
+ negotiation: NegotiationPolicy;
143
+ /** Execution policy settings */
144
+ execution: TaskExecutionPolicy;
145
+ /** Escalation policy settings */
146
+ escalation: EscalationPolicy;
147
+ /** Per-agent clamped preferences (optional) */
148
+ applied?: Record<string, AgentPreferences>;
149
+ /** Negotiation ID this policy applies to */
150
+ negotiationId?: string;
151
+ /** Timestamp when policy was created (ISO-8601 string) */
152
+ createdAt?: string;
153
+ }
154
+ /**
155
+ * A named policy profile.
156
+ */
157
+ export interface PolicyProfile {
158
+ /** Profile name (e.g., "LOW", "MEDIUM", "HIGH") */
159
+ name: string;
160
+ /** The negotiation policy for this profile */
161
+ negotiation: NegotiationPolicy;
162
+ /** The execution policy for this profile */
163
+ execution: TaskExecutionPolicy;
164
+ /** The escalation policy for this profile */
165
+ escalation: EscalationPolicy;
166
+ }
167
+ /**
168
+ * Error thrown when a policy operation fails.
169
+ */
170
+ export declare class PolicyStoreError extends Error {
171
+ constructor(message: string);
172
+ }
173
+ /**
174
+ * Interface for policy storage backends.
175
+ *
176
+ * Implementations provide storage and retrieval of negotiation policies.
177
+ * Policies are immutable once stored - saving a policy with the same
178
+ * policy_id but different version creates a new snapshot in the history.
179
+ */
180
+ export interface PolicyStore {
181
+ /**
182
+ * Get the latest version of a policy by its ID.
183
+ *
184
+ * @param policyId - The unique identifier of the policy
185
+ * @returns The effective policy if found, null otherwise
186
+ */
187
+ getPolicy(policyId: string): Promise<EffectivePolicy | null>;
188
+ /**
189
+ * Save a policy snapshot.
190
+ *
191
+ * If the policy does not have a version, one will be generated.
192
+ * The policy snapshot is immutable once saved.
193
+ *
194
+ * @param policy - The effective policy to save
195
+ * @returns The policy ID
196
+ */
197
+ savePolicy(policy: EffectivePolicy): Promise<string>;
198
+ /**
199
+ * List all policy IDs, optionally filtered by prefix.
200
+ *
201
+ * @param prefix - Optional prefix to filter policy IDs
202
+ * @returns List of matching policy IDs
203
+ */
204
+ listPolicies(prefix?: string): Promise<string[]>;
205
+ /**
206
+ * Delete a policy by its ID (removes all versions).
207
+ *
208
+ * @param policyId - The unique identifier of the policy
209
+ * @returns True if the policy was deleted, false if not found
210
+ */
211
+ deletePolicy(policyId: string): Promise<boolean>;
212
+ /**
213
+ * Retrieve the complete version history for a policy.
214
+ *
215
+ * Returns policies in chronological order (oldest to newest).
216
+ *
217
+ * @param policyId - The unique identifier of the policy
218
+ * @returns List of all versions of the policy
219
+ */
220
+ getHistory(policyId: string): Promise<EffectivePolicy[]>;
221
+ /**
222
+ * Get a policy profile by name.
223
+ *
224
+ * @param name - The profile name
225
+ * @returns The policy profile if found, null otherwise
226
+ */
227
+ getProfile(name: string): Promise<PolicyProfile | null>;
228
+ /**
229
+ * Save a policy profile.
230
+ *
231
+ * @param profile - The policy profile to save
232
+ * @returns The profile name
233
+ */
234
+ saveProfile(profile: PolicyProfile): Promise<string>;
235
+ /**
236
+ * List all profile names.
237
+ *
238
+ * @returns List of profile names
239
+ */
240
+ listProfiles(): Promise<string[]>;
241
+ }
242
+ /**
243
+ * Default negotiation policy.
244
+ *
245
+ * Used when no specific policy is configured.
246
+ */
247
+ export declare const DEFAULT_NEGOTIATION_POLICY: NegotiationPolicy;
248
+ /**
249
+ * In-memory implementation of PolicyStore.
250
+ *
251
+ * Provides a simple in-memory storage for policies and profiles with
252
+ * full version history support. Data is lost when the process terminates.
253
+ * Suitable for development and testing; production deployments should
254
+ * use JsonFilePolicyStore for persistence.
255
+ */
256
+ export declare class InMemoryPolicyStore implements PolicyStore {
257
+ private policies;
258
+ private profiles;
259
+ constructor();
260
+ /**
261
+ * Initialize default policy profiles.
262
+ */
263
+ private initializeDefaultProfiles;
264
+ /**
265
+ * Get the latest version of a policy by its ID.
266
+ *
267
+ * @param policyId - The unique identifier of the policy
268
+ * @returns The most recent effective policy if found, null otherwise
269
+ */
270
+ getPolicy(policyId: string): Promise<EffectivePolicy | null>;
271
+ /**
272
+ * Save a policy snapshot to the version history.
273
+ *
274
+ * If the policy does not have an ID, one will be generated.
275
+ * If the policy does not have a version, one will be generated.
276
+ *
277
+ * @param policy - The effective policy to save
278
+ * @returns The policy ID
279
+ */
280
+ savePolicy(policy: EffectivePolicy): Promise<string>;
281
+ /**
282
+ * List all policy IDs, optionally filtered by prefix.
283
+ *
284
+ * @param prefix - Optional prefix to filter policy IDs
285
+ * @returns List of matching policy IDs
286
+ */
287
+ listPolicies(prefix?: string): Promise<string[]>;
288
+ /**
289
+ * Delete a policy by its ID (removes all versions).
290
+ *
291
+ * @param policyId - The unique identifier of the policy
292
+ * @returns True if the policy was deleted, false if not found
293
+ */
294
+ deletePolicy(policyId: string): Promise<boolean>;
295
+ /**
296
+ * Retrieve the complete version history for a policy.
297
+ *
298
+ * Returns policies in chronological order (oldest to newest).
299
+ *
300
+ * @param policyId - The unique identifier of the policy
301
+ * @returns List of all versions of the policy
302
+ */
303
+ getHistory(policyId: string): Promise<EffectivePolicy[]>;
304
+ /**
305
+ * Get a policy profile by name.
306
+ *
307
+ * @param name - The profile name
308
+ * @returns The policy profile if found, null otherwise
309
+ */
310
+ getProfile(name: string): Promise<PolicyProfile | null>;
311
+ /**
312
+ * Save a policy profile.
313
+ *
314
+ * @param profile - The policy profile to save
315
+ * @returns The profile name
316
+ */
317
+ saveProfile(profile: PolicyProfile): Promise<string>;
318
+ /**
319
+ * List all profile names.
320
+ *
321
+ * @returns List of profile names
322
+ */
323
+ listProfiles(): Promise<string[]>;
324
+ /**
325
+ * Create an effective policy from a profile and agent preferences.
326
+ *
327
+ * Clamps agent preferences to the profile's guardrails.
328
+ *
329
+ * @param profileName - The profile to use as base
330
+ * @param agentPrefs - Optional agent preferences to apply
331
+ * @param negotiationId - Optional negotiation ID
332
+ * @returns The effective policy
333
+ * @throws PolicyStoreError if the profile does not exist
334
+ */
335
+ createEffectivePolicy(profileName: string, agentPrefs?: Record<string, AgentPreferences>, negotiationId?: string): Promise<EffectivePolicy>;
336
+ }
337
+ /**
338
+ * JSON file-based implementation of PolicyStore.
339
+ *
340
+ * Stores policies as JSON files on disk with full version history support.
341
+ * Each policy is stored in a separate file named `{sanitized_policy_id}.json`.
342
+ * Uses atomic writes (temp file + rename) to prevent corruption.
343
+ *
344
+ * Suitable for production use in single-node deployments.
345
+ */
346
+ export declare class JsonFilePolicyStore implements PolicyStore {
347
+ private readonly directory;
348
+ private profiles;
349
+ /**
350
+ * Create a new JSON file policy store.
351
+ *
352
+ * @param directory - Directory to store policy files
353
+ */
354
+ constructor(directory: string);
355
+ /**
356
+ * Initialize the store, creating the directory if needed.
357
+ */
358
+ initialize(): Promise<void>;
359
+ /**
360
+ * Initialize default policy profiles.
361
+ */
362
+ private initializeDefaultProfiles;
363
+ /**
364
+ * Sanitize a policy ID for use as a filename.
365
+ */
366
+ private sanitizeId;
367
+ /**
368
+ * Get the file path for a policy.
369
+ */
370
+ private getFilePath;
371
+ /**
372
+ * Load versions from a file.
373
+ */
374
+ private loadFromFile;
375
+ /**
376
+ * Save versions to a file atomically.
377
+ */
378
+ private saveToFile;
379
+ getPolicy(policyId: string): Promise<EffectivePolicy | null>;
380
+ savePolicy(policy: EffectivePolicy): Promise<string>;
381
+ listPolicies(prefix?: string): Promise<string[]>;
382
+ deletePolicy(policyId: string): Promise<boolean>;
383
+ getHistory(policyId: string): Promise<EffectivePolicy[]>;
384
+ getProfile(name: string): Promise<PolicyProfile | null>;
385
+ saveProfile(profile: PolicyProfile): Promise<string>;
386
+ listProfiles(): Promise<string[]>;
387
+ /**
388
+ * Create an effective policy from a profile and agent preferences.
389
+ */
390
+ createEffectivePolicy(profileName: string, agentPrefs?: Record<string, AgentPreferences>, negotiationId?: string): Promise<EffectivePolicy>;
391
+ }
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Voting and aggregation strategies for SW4RM.
3
+ *
4
+ * This module provides aggregation strategies for combining critic votes
5
+ * in negotiation room workflows. Strategies include:
6
+ * - SimpleAverageAggregator: Arithmetic mean of all scores
7
+ * - ConfidenceWeightedAggregator: Weight votes by confidence (POMDP-based)
8
+ * - MajorityVoteAggregator: Count passed vs failed votes
9
+ * - BordaCountAggregator: Ranked voting with position-based points
10
+ *
11
+ * Based on Python SDK voting/strategies.py and voting/aggregation.py.
12
+ */
13
+ import { NegotiationVote, AggregatedScore } from '../clients/negotiationRoom.js';
14
+ /**
15
+ * Interface for vote aggregation strategies.
16
+ *
17
+ * Implementations must provide an aggregate method that takes a list of votes
18
+ * and returns an AggregatedScore with statistical summary.
19
+ */
20
+ export interface VotingAggregator {
21
+ /**
22
+ * Aggregate votes into statistical summary.
23
+ *
24
+ * @param votes - List of critic votes to aggregate
25
+ * @returns AggregatedScore with aggregation results
26
+ * @throws NegotiationValidationError if votes list is empty or invalid
27
+ */
28
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
29
+ }
30
+ /**
31
+ * Simple arithmetic mean aggregation strategy.
32
+ *
33
+ * Computes basic statistics without considering confidence levels.
34
+ * All votes are weighted equally.
35
+ */
36
+ export declare class SimpleAverageAggregator implements VotingAggregator {
37
+ /**
38
+ * Aggregate votes using simple arithmetic mean.
39
+ *
40
+ * @param votes - List of critic votes to aggregate
41
+ * @returns AggregatedScore with simple mean in both mean and weightedMean fields
42
+ * @throws NegotiationValidationError if votes list is empty
43
+ */
44
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
45
+ }
46
+ /**
47
+ * Confidence-weighted aggregation strategy based on POMDP research.
48
+ *
49
+ * Weights each vote's score by its confidence value, giving more influence
50
+ * to votes from critics with higher certainty. This implements the approach
51
+ * from POMDP research where agent confidence reflects belief state certainty.
52
+ *
53
+ * Formula: weighted_mean = sum(score_i * confidence_i) / sum(confidence_i)
54
+ */
55
+ export declare class ConfidenceWeightedAggregator implements VotingAggregator {
56
+ /**
57
+ * Aggregate votes using confidence weighting.
58
+ *
59
+ * @param votes - List of critic votes to aggregate
60
+ * @returns AggregatedScore with confidence-weighted mean
61
+ * @throws NegotiationValidationError if votes list is empty
62
+ */
63
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
64
+ }
65
+ /**
66
+ * Majority voting aggregation strategy.
67
+ *
68
+ * Counts the number of passed vs failed votes and returns a score based on
69
+ * the majority outcome. This is a binary approach that ignores the numerical
70
+ * score values and focuses on the pass/fail decision.
71
+ *
72
+ * Score mapping:
73
+ * - All passed: 10.0
74
+ * - Majority passed (>50%): 7.5
75
+ * - Tie: 5.0
76
+ * - Majority failed (>50%): 2.5
77
+ * - All failed: 0.0
78
+ */
79
+ export declare class MajorityVoteAggregator implements VotingAggregator {
80
+ /**
81
+ * Aggregate votes using majority voting.
82
+ *
83
+ * @param votes - List of critic votes to aggregate
84
+ * @returns AggregatedScore with score based on majority outcome
85
+ * @throws NegotiationValidationError if votes list is empty
86
+ */
87
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
88
+ }
89
+ /**
90
+ * Borda count aggregation strategy.
91
+ *
92
+ * Implements ranked voting where each vote receives points based on its
93
+ * rank position. Higher scored votes receive more points.
94
+ *
95
+ * Ranking system:
96
+ * - Votes are sorted by score (highest to lowest)
97
+ * - Highest score receives n points (where n = number of votes)
98
+ * - Second highest receives n-1 points
99
+ * - Lowest score receives 1 point
100
+ * - Points are summed and normalized to 0-10 scale
101
+ *
102
+ * This method is resistant to strategic voting and reduces impact of outliers.
103
+ */
104
+ export declare class BordaCountAggregator implements VotingAggregator {
105
+ /**
106
+ * Aggregate votes using Borda count.
107
+ *
108
+ * @param votes - List of critic votes to aggregate
109
+ * @returns AggregatedScore with Borda count normalized score
110
+ * @throws NegotiationValidationError if votes list is empty
111
+ */
112
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
113
+ }
114
+ /**
115
+ * Main aggregator class with consensus and polarization detection.
116
+ *
117
+ * Wraps a VotingAggregator strategy and provides additional methods for
118
+ * analyzing vote distributions, detecting consensus, and identifying
119
+ * polarization.
120
+ */
121
+ export declare class VotingAnalyzer {
122
+ private strategy;
123
+ /**
124
+ * Initialize analyzer with a strategy.
125
+ *
126
+ * @param strategy - The aggregation strategy to use
127
+ */
128
+ constructor(strategy: VotingAggregator);
129
+ /**
130
+ * Aggregate votes using the configured strategy.
131
+ *
132
+ * @param votes - List of critic votes to aggregate
133
+ * @returns AggregatedScore with aggregation results
134
+ * @throws NegotiationValidationError if votes list is empty
135
+ */
136
+ aggregate(votes: NegotiationVote[]): AggregatedScore;
137
+ /**
138
+ * Compute Shannon entropy of vote distribution.
139
+ *
140
+ * Entropy measures the uncertainty or disorder in the vote distribution.
141
+ * Higher entropy indicates more disagreement/uncertainty, lower entropy
142
+ * indicates more consensus.
143
+ *
144
+ * The score range [0, 10] is divided into bins, and entropy is computed
145
+ * over the probability distribution of votes across bins.
146
+ *
147
+ * @param votes - List of critic votes
148
+ * @returns Entropy value in bits (0 = perfect consensus, higher = more uncertainty)
149
+ * @throws NegotiationValidationError if votes list is empty
150
+ */
151
+ computeEntropy(votes: NegotiationVote[]): number;
152
+ /**
153
+ * Detect if votes show strong consensus.
154
+ *
155
+ * Consensus is detected when:
156
+ * 1. Standard deviation of scores is low (< 2.0)
157
+ * 2. A large proportion of critics agree on pass/fail (>= threshold)
158
+ *
159
+ * @param votes - List of critic votes
160
+ * @param threshold - Minimum proportion of agreement required (default 0.8 = 80%)
161
+ * @returns True if consensus is detected, false otherwise
162
+ * @throws NegotiationValidationError if votes list is empty or threshold not in [0, 1]
163
+ */
164
+ detectConsensus(votes: NegotiationVote[], threshold?: number): boolean;
165
+ /**
166
+ * Detect if votes show polarization (bimodal distribution).
167
+ *
168
+ * Polarization is detected when votes cluster into two distinct groups,
169
+ * typically at opposite ends of the score spectrum. This is identified by:
170
+ * 1. High standard deviation (>= 3.0)
171
+ * 2. Low density in the middle range (4-6)
172
+ * 3. High density in the extremes (0-3 or 7-10)
173
+ *
174
+ * @param votes - List of critic votes
175
+ * @returns True if polarization is detected, false otherwise
176
+ * @throws NegotiationValidationError if votes list is empty
177
+ */
178
+ detectPolarization(votes: NegotiationVote[]): boolean;
179
+ /**
180
+ * Compute variance of confidence levels across votes.
181
+ *
182
+ * High variance in confidence suggests critics have different levels of
183
+ * certainty about their evaluations, which may indicate the artifact is
184
+ * harder to assess or has ambiguous quality.
185
+ *
186
+ * @param votes - List of critic votes
187
+ * @returns Variance of confidence values
188
+ * @throws NegotiationValidationError if votes list is empty
189
+ */
190
+ computeConfidenceVariance(votes: NegotiationVote[]): number;
191
+ /**
192
+ * Get comprehensive summary of vote characteristics.
193
+ *
194
+ * Combines multiple analytical methods to provide a complete picture
195
+ * of the vote distribution and critic agreement.
196
+ *
197
+ * @param votes - List of critic votes
198
+ * @returns Object with summary statistics
199
+ * @throws NegotiationValidationError if votes list is empty
200
+ */
201
+ getVoteSummary(votes: NegotiationVote[]): {
202
+ entropy: number;
203
+ consensus: boolean;
204
+ polarization: boolean;
205
+ confidenceVariance: number;
206
+ passRate: number;
207
+ };
208
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sw4rm/js-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "SW4RM Agentic Protocol JavaScript/TypeScript SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -14,7 +14,8 @@
14
14
  }
15
15
  },
16
16
  "scripts": {
17
- "build": "npm run build:proto && npm run build:lib",
17
+ "build": "npm run build:proto && npm run build:lib && npm run copy:protos",
18
+ "copy:protos": "rm -rf protos && cp -r ../../protos protos",
18
19
  "example": "tsx",
19
20
  "build:proto": "npm run proto:js && npm run proto:ts",
20
21
  "build:lib": "npm run build:esm && npm run build:cjs && npm run build:types",
@@ -30,6 +31,7 @@
30
31
  },
31
32
  "files": [
32
33
  "dist",
34
+ "protos",
33
35
  "README.md",
34
36
  "LICENSE"
35
37
  ],
@@ -0,0 +1,24 @@
1
+ syntax = "proto3";
2
+
3
+ package sw4rm.activity;
4
+
5
+ message Artifact {
6
+ string negotiation_id = 1;
7
+ string kind = 2; // contract|diff|decision|score|note
8
+ string version = 3; // e.g., v3
9
+ string content_type = 4;
10
+ bytes content = 5;
11
+ string created_at = 6; // ISO-8601
12
+ }
13
+
14
+ message AppendArtifactRequest { Artifact artifact = 1; }
15
+ message AppendArtifactResponse { bool ok = 1; string reason = 2; }
16
+
17
+ message ListArtifactsRequest { string negotiation_id = 1; string kind = 2; }
18
+ message ListArtifactsResponse { repeated Artifact items = 1; }
19
+
20
+ service ActivityService {
21
+ rpc AppendArtifact(AppendArtifactRequest) returns (AppendArtifactResponse);
22
+ rpc ListArtifacts(ListArtifactsRequest) returns (ListArtifactsResponse);
23
+ }
24
+