@cat-factory/consensus 0.17.12 → 0.17.13
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.
|
@@ -2,6 +2,22 @@ import type { ConsensusContribution } from '@cat-factory/kernel';
|
|
|
2
2
|
import type { ConsensusUsage, GenerateFn, ResolvedParticipant } from './types.js';
|
|
3
3
|
/** The default LLM call: a one-shot `generateText` tagged for the observability sink. */
|
|
4
4
|
export declare const defaultGenerate: GenerateFn;
|
|
5
|
+
/**
|
|
6
|
+
* The strategy's total across its calls. Kernel's fold, so the rule for an aggregate's input
|
|
7
|
+
* CLASS split is stated once for the companion repair retry and the consensus rounds alike:
|
|
8
|
+
* each part keeps its own split, and a part whose provider reported none folds in as fresh.
|
|
9
|
+
*
|
|
10
|
+
* A panel is the aggregate that rule was written for. Its parts are DIFFERENT MODELS behind
|
|
11
|
+
* different providers, and not all of them report cache details (`workers-ai-provider` reports
|
|
12
|
+
* none), so an all-or-nothing split would let one such participant re-price the whole panel's
|
|
13
|
+
* input at the fresh rate: the several-fold over-charge classed pricing exists to remove, on
|
|
14
|
+
* the shape that re-sends one goal prompt to every participant and is therefore mostly cache
|
|
15
|
+
* reads. Nothing here may re-state that rule locally; a strategy folds through kernel.
|
|
16
|
+
*
|
|
17
|
+
* The identity is `undefined` rather than a zeroed usage: a strategy that made no priced call
|
|
18
|
+
* has nothing to say about its classes, and a zero split would assert it cached nothing. Only
|
|
19
|
+
* the final total is coerced to a zero, since a strategy's declared usage is not optional.
|
|
20
|
+
*/
|
|
5
21
|
export declare function sumUsage(parts: ConsensusUsage[]): ConsensusUsage;
|
|
6
22
|
/** Stable anonymous label for a participant index, so peers can't anchor on identity. */
|
|
7
23
|
export declare function anonLabel(index: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/strategies/shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/strategies/shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAEhE,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EAEV,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAMnB,yFAAyF;AACzF,eAAO,MAAM,eAAe,EAAE,UAc7B,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,CAOhE;AAED,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,GAAG,MAAM,CAGxF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,qBAAqB,EAAE,EACtC,YAAY,EAAE,mBAAmB,EAAE,GAClC,MAAM,CAOR;AAED,mDAAmD;AACnD,eAAO,MAAM,kBAAkB,QAKpB,CAAA;AAEX;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACrB,MAAM,CAWR"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { generateText } from 'ai';
|
|
2
|
-
import { catFactoryObservability } from '@cat-factory/kernel';
|
|
2
|
+
import { catFactoryObservability, sumAgentTokenUsage } from '@cat-factory/kernel';
|
|
3
|
+
import { agentUsageFromModelUsage } from '@cat-factory/agents';
|
|
3
4
|
// Shared helpers for the consensus strategies: the default Vercel-AI-SDK `generate`
|
|
4
5
|
// implementation, usage accumulation, anonymization (so peers judge ideas, not authors),
|
|
5
6
|
// and the participant/synthesizer prompt builders that encode the debate best-practices.
|
|
@@ -17,20 +18,26 @@ export const defaultGenerate = async (args) => {
|
|
|
17
18
|
executionId: args.tags.executionId,
|
|
18
19
|
}),
|
|
19
20
|
});
|
|
20
|
-
return {
|
|
21
|
-
text: text.trim(),
|
|
22
|
-
usage: { inputTokens: usage.inputTokens ?? 0, outputTokens: usage.outputTokens ?? 0 },
|
|
23
|
-
};
|
|
21
|
+
return { text: text.trim(), usage: agentUsageFromModelUsage(usage) };
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The strategy's total across its calls. Kernel's fold, so the rule for an aggregate's input
|
|
25
|
+
* CLASS split is stated once for the companion repair retry and the consensus rounds alike:
|
|
26
|
+
* each part keeps its own split, and a part whose provider reported none folds in as fresh.
|
|
27
|
+
*
|
|
28
|
+
* A panel is the aggregate that rule was written for. Its parts are DIFFERENT MODELS behind
|
|
29
|
+
* different providers, and not all of them report cache details (`workers-ai-provider` reports
|
|
30
|
+
* none), so an all-or-nothing split would let one such participant re-price the whole panel's
|
|
31
|
+
* input at the fresh rate: the several-fold over-charge classed pricing exists to remove, on
|
|
32
|
+
* the shape that re-sends one goal prompt to every participant and is therefore mostly cache
|
|
33
|
+
* reads. Nothing here may re-state that rule locally; a strategy folds through kernel.
|
|
34
|
+
*
|
|
35
|
+
* The identity is `undefined` rather than a zeroed usage: a strategy that made no priced call
|
|
36
|
+
* has nothing to say about its classes, and a zero split would assert it cached nothing. Only
|
|
37
|
+
* the final total is coerced to a zero, since a strategy's declared usage is not optional.
|
|
38
|
+
*/
|
|
32
39
|
export function sumUsage(parts) {
|
|
33
|
-
return parts.reduce(
|
|
40
|
+
return (parts.reduce((total, part) => sumAgentTokenUsage(total, part), undefined) ?? { inputTokens: 0, outputTokens: 0 });
|
|
34
41
|
}
|
|
35
42
|
/** Stable anonymous label for a participant index, so peers can't anchor on identity. */
|
|
36
43
|
export function anonLabel(index) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/strategies/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/strategies/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACjC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAEjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAS9D,oFAAoF;AACpF,yFAAyF;AACzF,yFAAyF;AAEzF,yFAAyF;AACzF,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAAE,IAAkB,EAA2B,EAAE;IAC/F,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,YAAY,CAAC;QACzC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CAAC,IAAI,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxF,eAAe,EAAE,uBAAuB,CAAC;YACvC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC9B,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;YAClC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;SACnC,CAAC;KAC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AAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAA;AACjB,CAAC;AAED,mDAAmD;AACnD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,uGAAuG;IACvG,gGAAgG;IAChG,sLAAsL;IACtL,qJAAqJ;CACtJ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAEX;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,UAAkB,EAClB,QAAgB,EAChB,cAAsB;IAEtB,OAAO;QACL,OAAO;QACP,UAAU;QACV,EAAE;QACF,4CAA4C;QAC5C,EAAE;QACF,QAAQ;QACR,EAAE;QACF,cAAc;KACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { LanguageModel } from 'ai';
|
|
2
|
-
import type { ConsensusRound, ConsensusSessionStatus } from '@cat-factory/kernel';
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type { AgentTokenUsage, ConsensusRound, ConsensusSessionStatus } from '@cat-factory/kernel';
|
|
3
|
+
/**
|
|
4
|
+
* Token usage accumulated across a strategy's LLM calls.
|
|
5
|
+
*
|
|
6
|
+
* Kernel's {@link AgentTokenUsage} rather than a structural twin of it, because a strategy's
|
|
7
|
+
* total becomes the step's reported usage verbatim: a local copy of the two totals silently
|
|
8
|
+
* dropped the input CLASS split on the way out, and a panel re-sending one goal prompt to
|
|
9
|
+
* several participants is exactly the shape whose input is mostly cache reads.
|
|
10
|
+
*/
|
|
11
|
+
export type ConsensusUsage = AgentTokenUsage;
|
|
8
12
|
/** A participant with its model resolved to a concrete handle. */
|
|
9
13
|
export interface ResolvedParticipant {
|
|
10
14
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/strategies/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,M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MAAM,CAAA;IAClB,uFAAuF;IACvF,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,mBAAmB,EAAE,CAAA;IACnC,WAAW,EAAE;QAAE,KAAK,EAAE,aAAa,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;IACzD,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,UAAU,CAAA;IACpB,IAAI,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE;QACpB,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,MAAM,EAAE,sBAAsB,CAAA;KAC/B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAA;IACjB,2FAA2F;IAC3F,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,oEAAoE;IACpE,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,EAAE,cAAc,CAAA;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cat-factory/consensus",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.13",
|
|
4
4
|
"description": "Optional consensus-orchestration mechanism (specialist panel / debate / ranked voting) for cat-factory agent steps, with task-estimate gating.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@cat-factory/agents": "0.145.
|
|
27
|
+
"@cat-factory/agents": "0.145.2",
|
|
28
28
|
"@cat-factory/contracts": "0.331.0",
|
|
29
|
-
"@cat-factory/kernel": "0.321.
|
|
29
|
+
"@cat-factory/kernel": "0.321.2",
|
|
30
30
|
"ai": "^7.0.77"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|