@babav/knowledge-core-client 0.59.0 → 0.60.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/dist/index.d.ts CHANGED
@@ -688,6 +688,45 @@ export interface CitationArm {
688
688
  n_questions: number | null;
689
689
  note: string | null;
690
690
  }
691
+ /** Per-model cost split within a stage. `actual_usd` is cache-discounted (matches the bill);
692
+ * `representative_usd` is the as-if-uncached headline. */
693
+ export interface CostByModel {
694
+ calls: number;
695
+ representative_usd: number;
696
+ actual_usd: number;
697
+ avg_actual_usd_per_query: number;
698
+ }
699
+ /** Cost of one pipeline stage (generate | rewrite | decompose | multi_query | inspect | citation |
700
+ * groundedness | title | embedding | visual_concept | visual_vet | visual_proposer | visual_claims |
701
+ * visual_vision_judge), split by model. */
702
+ export interface CostByStage {
703
+ calls: number;
704
+ representative_usd: number;
705
+ actual_usd: number;
706
+ avg_actual_usd_per_query: number;
707
+ by_model: Record<string, CostByModel>;
708
+ }
709
+ /** Per-profile cost analytics (GET /v1/query-profiles/{id}/cost). By default reflects the profile's
710
+ * CURRENT config only (`config_fingerprint`); `current_config_pending` is true right after a
711
+ * cost-impacting change, before any query has run under the new config (so totals are 0 until then).
712
+ * `by_stage` covers the whole text + visual pipeline. `breakdown_capped` => the stage/model split was
713
+ * computed from the most recent `breakdown_from_n` queries (top-line totals are exact regardless). */
714
+ export interface CostSummary {
715
+ query_profile_id: string | null;
716
+ config_fingerprint: string | null;
717
+ all_configs: boolean;
718
+ current_config_pending: boolean;
719
+ since_days: number;
720
+ price_sheet_version: string;
721
+ n_queries: number;
722
+ total_actual_usd: number;
723
+ total_representative_usd: number;
724
+ avg_actual_usd_per_query: number;
725
+ avg_representative_usd_per_query: number;
726
+ breakdown_from_n: number;
727
+ breakdown_capped: boolean;
728
+ by_stage: Record<string, CostByStage>;
729
+ }
691
730
  /** Citation-benchmark leaderboard (GET /v1/benchmark/citations) — per configuration: citation
692
731
  * precision + yield + cost + latency. Native citations (~1.0 by construction) vs post-hoc (lower
693
732
  * ceiling); each arm's `mechanism` says which. `arms` empty if no citation benchmark has run. */
@@ -1138,6 +1177,16 @@ export declare class KnowledgeCoreClient extends HttpBase {
1138
1177
  }) => Promise<QueryProfile>;
1139
1178
  update: (id: UUID, b: QueryProfileWrite) => Promise<QueryProfile>;
1140
1179
  delete: (id: UUID) => Promise<void>;
1180
+ /** Per-profile COST analytics (GET /v1/query-profiles/{id}/cost): per-query averages + totals,
1181
+ * broken down by stage and model, over the last `sinceDays` (default 30). By default only the
1182
+ * profile's CURRENT config is counted (so the numbers reflect the live config; a cost-impacting
1183
+ * change auto-resets — `current_config_pending` is true until the first query under the new config).
1184
+ * `allConfigs: true` aggregates every config the profile has run under. `actual_usd` matches the
1185
+ * provider bill (cache-discounted); `representative_usd` is the as-if-uncached headline. */
1186
+ cost: (id: UUID, opts?: {
1187
+ sinceDays?: number;
1188
+ allConfigs?: boolean;
1189
+ }) => Promise<CostSummary>;
1141
1190
  /** The model catalog for an query-profile-config UI: supported models + default per field, per-model
1142
1191
  * capabilities (`supports_reasoning`), and mode↔model dependencies. */
1143
1192
  modelOptions: () => Promise<ModelOptions>;
package/dist/index.js CHANGED
@@ -465,6 +465,13 @@ export class KnowledgeCoreClient extends HttpBase {
465
465
  create: (b) => this.request("POST", "/v1/query-profiles", { json: b }),
466
466
  update: (id, b) => this.request("PATCH", `/v1/query-profiles/${id}`, { json: b }),
467
467
  delete: (id) => this.request("DELETE", `/v1/query-profiles/${id}`),
468
+ /** Per-profile COST analytics (GET /v1/query-profiles/{id}/cost): per-query averages + totals,
469
+ * broken down by stage and model, over the last `sinceDays` (default 30). By default only the
470
+ * profile's CURRENT config is counted (so the numbers reflect the live config; a cost-impacting
471
+ * change auto-resets — `current_config_pending` is true until the first query under the new config).
472
+ * `allConfigs: true` aggregates every config the profile has run under. `actual_usd` matches the
473
+ * provider bill (cache-discounted); `representative_usd` is the as-if-uncached headline. */
474
+ cost: (id, opts) => this.request("GET", `/v1/query-profiles/${id}/cost`, { query: { since_days: opts?.sinceDays, all_configs: opts?.allConfigs } }),
468
475
  /** The model catalog for an query-profile-config UI: supported models + default per field, per-model
469
476
  * capabilities (`supports_reasoning`), and mode↔model dependencies. */
470
477
  modelOptions: () => this.request("GET", "/v1/query-profiles/model-options"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babav/knowledge-core-client",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "TypeScript client for the Babav Knowledge Core API (Deno + Node 18+, zero deps). Includes the babav.visual grammar TYPES at the ./visual subpath (types only; all visual rendering is server-side).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -657,6 +657,45 @@ export interface CitationArm {
657
657
  n_questions: number | null;
658
658
  note: string | null;
659
659
  }
660
+ /** Per-model cost split within a stage. `actual_usd` is cache-discounted (matches the bill);
661
+ * `representative_usd` is the as-if-uncached headline. */
662
+ export interface CostByModel {
663
+ calls: number;
664
+ representative_usd: number;
665
+ actual_usd: number;
666
+ avg_actual_usd_per_query: number;
667
+ }
668
+ /** Cost of one pipeline stage (generate | rewrite | decompose | multi_query | inspect | citation |
669
+ * groundedness | title | embedding | visual_concept | visual_vet | visual_proposer | visual_claims |
670
+ * visual_vision_judge), split by model. */
671
+ export interface CostByStage {
672
+ calls: number;
673
+ representative_usd: number;
674
+ actual_usd: number;
675
+ avg_actual_usd_per_query: number;
676
+ by_model: Record<string, CostByModel>;
677
+ }
678
+ /** Per-profile cost analytics (GET /v1/query-profiles/{id}/cost). By default reflects the profile's
679
+ * CURRENT config only (`config_fingerprint`); `current_config_pending` is true right after a
680
+ * cost-impacting change, before any query has run under the new config (so totals are 0 until then).
681
+ * `by_stage` covers the whole text + visual pipeline. `breakdown_capped` => the stage/model split was
682
+ * computed from the most recent `breakdown_from_n` queries (top-line totals are exact regardless). */
683
+ export interface CostSummary {
684
+ query_profile_id: string | null;
685
+ config_fingerprint: string | null; // null => aggregated across all configs (all_configs=true) or none yet
686
+ all_configs: boolean;
687
+ current_config_pending: boolean;
688
+ since_days: number;
689
+ price_sheet_version: string;
690
+ n_queries: number;
691
+ total_actual_usd: number;
692
+ total_representative_usd: number;
693
+ avg_actual_usd_per_query: number;
694
+ avg_representative_usd_per_query: number;
695
+ breakdown_from_n: number;
696
+ breakdown_capped: boolean;
697
+ by_stage: Record<string, CostByStage>;
698
+ }
660
699
  /** Citation-benchmark leaderboard (GET /v1/benchmark/citations) — per configuration: citation
661
700
  * precision + yield + cost + latency. Native citations (~1.0 by construction) vs post-hoc (lower
662
701
  * ceiling); each arm's `mechanism` says which. `arms` empty if no citation benchmark has run. */
@@ -1285,6 +1324,15 @@ export class KnowledgeCoreClient extends HttpBase {
1285
1324
  create: (b: QueryProfileWrite & { name: string }) => this.request<QueryProfile>("POST", "/v1/query-profiles", { json: b }),
1286
1325
  update: (id: UUID, b: QueryProfileWrite) => this.request<QueryProfile>("PATCH", `/v1/query-profiles/${id}`, { json: b }),
1287
1326
  delete: (id: UUID) => this.request<void>("DELETE", `/v1/query-profiles/${id}`),
1327
+ /** Per-profile COST analytics (GET /v1/query-profiles/{id}/cost): per-query averages + totals,
1328
+ * broken down by stage and model, over the last `sinceDays` (default 30). By default only the
1329
+ * profile's CURRENT config is counted (so the numbers reflect the live config; a cost-impacting
1330
+ * change auto-resets — `current_config_pending` is true until the first query under the new config).
1331
+ * `allConfigs: true` aggregates every config the profile has run under. `actual_usd` matches the
1332
+ * provider bill (cache-discounted); `representative_usd` is the as-if-uncached headline. */
1333
+ cost: (id: UUID, opts?: { sinceDays?: number; allConfigs?: boolean }) =>
1334
+ this.request<CostSummary>("GET", `/v1/query-profiles/${id}/cost`,
1335
+ { query: { since_days: opts?.sinceDays, all_configs: opts?.allConfigs } }),
1288
1336
  /** The model catalog for an query-profile-config UI: supported models + default per field, per-model
1289
1337
  * capabilities (`supports_reasoning`), and mode↔model dependencies. */
1290
1338
  modelOptions: () => this.request<ModelOptions>("GET", "/v1/query-profiles/model-options"),