@sebastientang/llm-council 0.2.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,393 @@
1
+ import { z } from 'zod';
2
+
3
+ interface CompletionRequest {
4
+ model: string;
5
+ systemPrompt: string;
6
+ messages: Array<{
7
+ role: 'user' | 'assistant';
8
+ content: string;
9
+ }>;
10
+ temperature?: number;
11
+ maxTokens?: number;
12
+ }
13
+ interface CompletionResponse {
14
+ content: string;
15
+ tokenCount: {
16
+ input: number;
17
+ output: number;
18
+ };
19
+ model: string;
20
+ }
21
+ interface LLMProvider {
22
+ id: string;
23
+ complete(request: CompletionRequest): Promise<CompletionResponse>;
24
+ }
25
+ declare const ParticipantSchema: z.ZodObject<{
26
+ id: z.ZodString;
27
+ name: z.ZodString;
28
+ provider: z.ZodString;
29
+ model: z.ZodString;
30
+ systemPrompt: z.ZodString;
31
+ temperature: z.ZodOptional<z.ZodNumber>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ id: string;
34
+ name: string;
35
+ provider: string;
36
+ model: string;
37
+ systemPrompt: string;
38
+ temperature?: number | undefined;
39
+ }, {
40
+ id: string;
41
+ name: string;
42
+ provider: string;
43
+ model: string;
44
+ systemPrompt: string;
45
+ temperature?: number | undefined;
46
+ }>;
47
+ type Participant = z.infer<typeof ParticipantSchema>;
48
+ interface PromptRequest {
49
+ participantId: string;
50
+ provider: string;
51
+ model: string;
52
+ systemPrompt: string;
53
+ userMessage: string;
54
+ temperature?: number;
55
+ maxTokens?: number;
56
+ }
57
+ interface Protocol {
58
+ buildPrompts(config: DeliberationConfig, history: DeliberationMessage[], round: number): PromptRequest[];
59
+ getRoundCount(): number;
60
+ }
61
+ declare const SynthesisSchema: z.ZodObject<{
62
+ recommendation: z.ZodString;
63
+ confidence: z.ZodNumber;
64
+ reasoning: z.ZodString;
65
+ risks: z.ZodArray<z.ZodString, "many">;
66
+ dissent: z.ZodArray<z.ZodString, "many">;
67
+ validationGates: z.ZodArray<z.ZodString, "many">;
68
+ assumptions: z.ZodArray<z.ZodString, "many">;
69
+ raw: z.ZodString;
70
+ }, "strip", z.ZodTypeAny, {
71
+ recommendation: string;
72
+ confidence: number;
73
+ reasoning: string;
74
+ risks: string[];
75
+ dissent: string[];
76
+ validationGates: string[];
77
+ assumptions: string[];
78
+ raw: string;
79
+ }, {
80
+ recommendation: string;
81
+ confidence: number;
82
+ reasoning: string;
83
+ risks: string[];
84
+ dissent: string[];
85
+ validationGates: string[];
86
+ assumptions: string[];
87
+ raw: string;
88
+ }>;
89
+ type Synthesis = z.infer<typeof SynthesisSchema>;
90
+ interface Synthesizer {
91
+ synthesize(config: DeliberationConfig, messages: DeliberationMessage[], provider: LLMProvider): Promise<Synthesis>;
92
+ }
93
+ declare const DeliberationMessageSchema: z.ZodObject<{
94
+ participantId: z.ZodString;
95
+ participantName: z.ZodString;
96
+ round: z.ZodNumber;
97
+ content: z.ZodString;
98
+ timestamp: z.ZodDate;
99
+ tokenCount: z.ZodObject<{
100
+ input: z.ZodNumber;
101
+ output: z.ZodNumber;
102
+ }, "strip", z.ZodTypeAny, {
103
+ input: number;
104
+ output: number;
105
+ }, {
106
+ input: number;
107
+ output: number;
108
+ }>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ participantId: string;
111
+ participantName: string;
112
+ round: number;
113
+ content: string;
114
+ timestamp: Date;
115
+ tokenCount: {
116
+ input: number;
117
+ output: number;
118
+ };
119
+ }, {
120
+ participantId: string;
121
+ participantName: string;
122
+ round: number;
123
+ content: string;
124
+ timestamp: Date;
125
+ tokenCount: {
126
+ input: number;
127
+ output: number;
128
+ };
129
+ }>;
130
+ type DeliberationMessage = z.infer<typeof DeliberationMessageSchema>;
131
+ declare const DeliberationConfigSchema: z.ZodObject<{
132
+ topic: z.ZodString;
133
+ options: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
134
+ context: z.ZodOptional<z.ZodString>;
135
+ preferredOption: z.ZodOptional<z.ZodString>;
136
+ participants: z.ZodArray<z.ZodObject<{
137
+ id: z.ZodString;
138
+ name: z.ZodString;
139
+ provider: z.ZodString;
140
+ model: z.ZodString;
141
+ systemPrompt: z.ZodString;
142
+ temperature: z.ZodOptional<z.ZodNumber>;
143
+ }, "strip", z.ZodTypeAny, {
144
+ id: string;
145
+ name: string;
146
+ provider: string;
147
+ model: string;
148
+ systemPrompt: string;
149
+ temperature?: number | undefined;
150
+ }, {
151
+ id: string;
152
+ name: string;
153
+ provider: string;
154
+ model: string;
155
+ systemPrompt: string;
156
+ temperature?: number | undefined;
157
+ }>, "many">;
158
+ rounds: z.ZodDefault<z.ZodNumber>;
159
+ tokenBudget: z.ZodOptional<z.ZodObject<{
160
+ perResponse: z.ZodOptional<z.ZodNumber>;
161
+ total: z.ZodOptional<z.ZodNumber>;
162
+ }, "strip", z.ZodTypeAny, {
163
+ perResponse?: number | undefined;
164
+ total?: number | undefined;
165
+ }, {
166
+ perResponse?: number | undefined;
167
+ total?: number | undefined;
168
+ }>>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ topic: string;
171
+ participants: {
172
+ id: string;
173
+ name: string;
174
+ provider: string;
175
+ model: string;
176
+ systemPrompt: string;
177
+ temperature?: number | undefined;
178
+ }[];
179
+ rounds: number;
180
+ options?: string[] | undefined;
181
+ context?: string | undefined;
182
+ preferredOption?: string | undefined;
183
+ tokenBudget?: {
184
+ perResponse?: number | undefined;
185
+ total?: number | undefined;
186
+ } | undefined;
187
+ }, {
188
+ topic: string;
189
+ participants: {
190
+ id: string;
191
+ name: string;
192
+ provider: string;
193
+ model: string;
194
+ systemPrompt: string;
195
+ temperature?: number | undefined;
196
+ }[];
197
+ options?: string[] | undefined;
198
+ context?: string | undefined;
199
+ preferredOption?: string | undefined;
200
+ rounds?: number | undefined;
201
+ tokenBudget?: {
202
+ perResponse?: number | undefined;
203
+ total?: number | undefined;
204
+ } | undefined;
205
+ }>;
206
+ type DeliberationConfig = z.infer<typeof DeliberationConfigSchema>;
207
+ declare const DeliberationMetadataSchema: z.ZodObject<{
208
+ totalTokens: z.ZodObject<{
209
+ input: z.ZodNumber;
210
+ output: z.ZodNumber;
211
+ }, "strip", z.ZodTypeAny, {
212
+ input: number;
213
+ output: number;
214
+ }, {
215
+ input: number;
216
+ output: number;
217
+ }>;
218
+ durationMs: z.ZodNumber;
219
+ modelBreakdown: z.ZodRecord<z.ZodString, z.ZodObject<{
220
+ input: z.ZodNumber;
221
+ output: z.ZodNumber;
222
+ }, "strip", z.ZodTypeAny, {
223
+ input: number;
224
+ output: number;
225
+ }, {
226
+ input: number;
227
+ output: number;
228
+ }>>;
229
+ }, "strip", z.ZodTypeAny, {
230
+ totalTokens: {
231
+ input: number;
232
+ output: number;
233
+ };
234
+ durationMs: number;
235
+ modelBreakdown: Record<string, {
236
+ input: number;
237
+ output: number;
238
+ }>;
239
+ }, {
240
+ totalTokens: {
241
+ input: number;
242
+ output: number;
243
+ };
244
+ durationMs: number;
245
+ modelBreakdown: Record<string, {
246
+ input: number;
247
+ output: number;
248
+ }>;
249
+ }>;
250
+ type DeliberationMetadata = z.infer<typeof DeliberationMetadataSchema>;
251
+ interface DeliberationResult {
252
+ config: DeliberationConfig;
253
+ messages: DeliberationMessage[];
254
+ synthesis: Synthesis;
255
+ metadata: DeliberationMetadata;
256
+ }
257
+ type CouncilEvents = {
258
+ 'round:start': {
259
+ round: number;
260
+ participantCount: number;
261
+ };
262
+ response: DeliberationMessage;
263
+ 'synthesis:start': undefined;
264
+ complete: DeliberationResult;
265
+ error: Error;
266
+ };
267
+
268
+ interface CouncilOptions {
269
+ providers: Map<string, LLMProvider>;
270
+ protocol: Protocol;
271
+ synthesizer: Synthesizer;
272
+ synthesisProvider?: {
273
+ providerId: string;
274
+ model: string;
275
+ };
276
+ }
277
+ declare class Council {
278
+ private providers;
279
+ private protocol;
280
+ private synthesizer;
281
+ private synthesisProvider;
282
+ private emitter;
283
+ constructor(options: CouncilOptions);
284
+ on<K extends keyof CouncilEvents>(event: K, handler: (payload: CouncilEvents[K]) => void): void;
285
+ off<K extends keyof CouncilEvents>(event: K, handler: (payload: CouncilEvents[K]) => void): void;
286
+ deliberate(rawConfig: DeliberationConfig): Promise<DeliberationResult>;
287
+ }
288
+
289
+ interface AnthropicProviderConfig {
290
+ apiKey: string;
291
+ defaultModel?: string;
292
+ defaultMaxTokens?: number;
293
+ }
294
+ declare class AnthropicProvider implements LLMProvider {
295
+ readonly id: "anthropic";
296
+ private client;
297
+ private defaultModel;
298
+ private defaultMaxTokens;
299
+ constructor(config: AnthropicProviderConfig);
300
+ complete(request: CompletionRequest): Promise<CompletionResponse>;
301
+ }
302
+
303
+ interface OpenRouterProviderConfig {
304
+ apiKey: string;
305
+ appName?: string;
306
+ defaultModel?: string;
307
+ defaultMaxTokens?: number;
308
+ siteUrl?: string;
309
+ }
310
+ declare class OpenRouterProvider implements LLMProvider {
311
+ readonly id: "openrouter";
312
+ private readonly apiKey;
313
+ private readonly appName;
314
+ private readonly defaultModel;
315
+ private readonly defaultMaxTokens;
316
+ private readonly siteUrl;
317
+ constructor(config: OpenRouterProviderConfig);
318
+ complete(request: CompletionRequest): Promise<CompletionResponse>;
319
+ }
320
+
321
+ interface AdversarialProtocolOptions {
322
+ rebuttalGuidance?: Record<string, string>;
323
+ }
324
+ declare class AdversarialProtocol implements Protocol {
325
+ private readonly rebuttalGuidance;
326
+ constructor(options?: AdversarialProtocolOptions);
327
+ getRoundCount(): number;
328
+ buildPrompts(config: DeliberationConfig, history: DeliberationMessage[], round: number): PromptRequest[];
329
+ private buildInitialBriefs;
330
+ private buildRebuttals;
331
+ }
332
+
333
+ interface PeerReviewProtocolOptions {
334
+ enableRevote?: boolean;
335
+ }
336
+ declare class PeerReviewProtocol implements Protocol {
337
+ private readonly enableRevote;
338
+ constructor(options?: PeerReviewProtocolOptions);
339
+ getRoundCount(): number;
340
+ buildPrompts(config: DeliberationConfig, history: DeliberationMessage[], round: number): PromptRequest[];
341
+ private buildInitialBriefs;
342
+ private buildRankingRound;
343
+ private buildRevoteRound;
344
+ }
345
+
346
+ interface ChairmanSynthesizerOptions {
347
+ model?: string;
348
+ temperature?: number;
349
+ }
350
+ declare class ChairmanSynthesizer implements Synthesizer {
351
+ private readonly model;
352
+ private readonly temperature;
353
+ constructor(options?: ChairmanSynthesizerOptions);
354
+ synthesize(config: DeliberationConfig, messages: DeliberationMessage[], provider: LLMProvider): Promise<Synthesis>;
355
+ }
356
+
357
+ interface DialecticalSynthesizerOptions {
358
+ model?: string;
359
+ temperature?: number;
360
+ }
361
+ declare class DialecticalSynthesizer implements Synthesizer {
362
+ private readonly model;
363
+ private readonly temperature;
364
+ constructor(options?: DialecticalSynthesizerOptions);
365
+ synthesize(config: DeliberationConfig, messages: DeliberationMessage[], provider: LLMProvider): Promise<Synthesis>;
366
+ }
367
+
368
+ type PersonaPreset = Omit<Participant, 'provider' | 'model'>;
369
+ declare const PERSONAS: {
370
+ readonly proposer: PersonaPreset;
371
+ readonly challenger: PersonaPreset;
372
+ readonly steelmanner: PersonaPreset;
373
+ readonly preMortem: PersonaPreset;
374
+ };
375
+ type PersonaId = keyof typeof PERSONAS;
376
+
377
+ interface AnonymizationMap {
378
+ labelToParticipant: Map<string, string>;
379
+ participantToLabel: Map<string, string>;
380
+ }
381
+ declare function createAnonymizationMap(participantIds: string[]): AnonymizationMap;
382
+ declare function anonymizeMessages(messages: DeliberationMessage[], map: AnonymizationMap): Array<{
383
+ label: string;
384
+ content: string;
385
+ }>;
386
+ declare function deanonymizeLabel(label: string, map: AnonymizationMap): string | undefined;
387
+
388
+ declare function buildInitialUserMessage(config: DeliberationConfig): string;
389
+
390
+ declare function buildSynthesisUserMessage(config: DeliberationConfig, messages: DeliberationMessage[]): string;
391
+ declare function parseSynthesisResponse(raw: string): Synthesis;
392
+
393
+ export { AdversarialProtocol, type AnonymizationMap, AnthropicProvider, ChairmanSynthesizer, type CompletionRequest, type CompletionResponse, Council, type CouncilEvents, type CouncilOptions, type DeliberationConfig, DeliberationConfigSchema, type DeliberationMessage, DeliberationMessageSchema, type DeliberationMetadata, DeliberationMetadataSchema, type DeliberationResult, DialecticalSynthesizer, type LLMProvider, OpenRouterProvider, PERSONAS, type Participant, ParticipantSchema, PeerReviewProtocol, type PersonaId, type PromptRequest, type Protocol, type Synthesis, SynthesisSchema, type Synthesizer, anonymizeMessages, buildInitialUserMessage, buildSynthesisUserMessage, createAnonymizationMap, deanonymizeLabel, parseSynthesisResponse };