@nodaro/shared 1.11.0 → 1.12.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.cjs +51 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -7
- package/dist/index.d.ts +31 -7
- package/dist/index.js +49 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/video-analysis-pricing.test.ts +29 -3
- package/src/index.ts +4 -0
- package/src/llm-models.ts +36 -9
- package/src/model-catalog.ts +20 -0
- package/src/video-analysis-pricing.ts +19 -1
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "../video-analysis-pricing.js"
|
|
8
8
|
import {
|
|
9
9
|
VIDEO_ANALYSIS_LLM_MODELS, VIDEO_ANALYSIS_TIERS, VIDEO_ANALYSIS_TIER_ORDER,
|
|
10
|
+
VIDEO_ANALYSIS_MIXED_TIERS,
|
|
10
11
|
DEFAULT_VIDEO_ANALYSIS_TIER, DEFAULT_VIDEO_ANALYSIS_MODEL, resolveVideoAnalysisModel,
|
|
11
12
|
} from "../llm-models.js"
|
|
12
13
|
|
|
@@ -43,26 +44,51 @@ describe("video-analysis-pricing", () => {
|
|
|
43
44
|
expect(VIDEO_ANALYSIS_LLM_MODELS).toEqual(["gemini-3-flash", "gemini-3.1-pro"])
|
|
44
45
|
})
|
|
45
46
|
|
|
46
|
-
it("tier layer: every tier maps to a real model AND every model is tier-reachable (no vendor leak)", () => {
|
|
47
|
+
it("tier layer: every model-backed tier maps to a real model AND every model is tier-reachable (no vendor leak)", () => {
|
|
47
48
|
// Adding a video-analysis model without a tier would silently leave it
|
|
48
49
|
// unreachable / unnamed — this fails until a tier decision is made.
|
|
49
50
|
const tierTargets = Object.values(VIDEO_ANALYSIS_TIERS)
|
|
50
51
|
for (const m of tierTargets) expect(VIDEO_ANALYSIS_LLM_MODELS).toContain(m)
|
|
51
52
|
for (const m of VIDEO_ANALYSIS_LLM_MODELS) expect(tierTargets).toContain(m)
|
|
52
|
-
|
|
53
|
+
// TIER_ORDER = model-backed tiers + mixed roll-plan tiers, exactly.
|
|
54
|
+
expect(new Set(VIDEO_ANALYSIS_TIER_ORDER)).toEqual(
|
|
55
|
+
new Set([...Object.keys(VIDEO_ANALYSIS_TIERS), ...VIDEO_ANALYSIS_MIXED_TIERS]),
|
|
56
|
+
)
|
|
57
|
+
// Mixed tiers are SENTINELS, never model ids — a mixed id leaking into the
|
|
58
|
+
// model list would break the roll-plan dispatch in the analysis engine.
|
|
59
|
+
for (const t of VIDEO_ANALYSIS_MIXED_TIERS) expect(VIDEO_ANALYSIS_LLM_MODELS).not.toContain(t)
|
|
53
60
|
})
|
|
54
61
|
|
|
55
|
-
it("resolveVideoAnalysisModel: tier → model, raw model passthrough, default pro on empty/unknown", () => {
|
|
62
|
+
it("resolveVideoAnalysisModel: tier → model, mixed → sentinel, raw model passthrough, default pro on empty/unknown", () => {
|
|
56
63
|
expect(DEFAULT_VIDEO_ANALYSIS_TIER).toBe("pro")
|
|
57
64
|
expect(DEFAULT_VIDEO_ANALYSIS_MODEL).toBe("gemini-3.1-pro")
|
|
58
65
|
expect(resolveVideoAnalysisModel("pro")).toBe("gemini-3.1-pro")
|
|
59
66
|
expect(resolveVideoAnalysisModel("fast")).toBe("gemini-3-flash")
|
|
67
|
+
expect(resolveVideoAnalysisModel("mixed")).toBe("mixed") // roll-plan sentinel passthrough
|
|
68
|
+
expect(resolveVideoAnalysisModel("mixed-fast")).toBe("mixed-fast")
|
|
60
69
|
expect(resolveVideoAnalysisModel("gemini-3-flash")).toBe("gemini-3-flash") // raw passthrough
|
|
61
70
|
expect(resolveVideoAnalysisModel(undefined)).toBe("gemini-3.1-pro") // default → pro
|
|
62
71
|
expect(resolveVideoAnalysisModel("")).toBe("gemini-3.1-pro")
|
|
63
72
|
expect(resolveVideoAnalysisModel("nonsense")).toBe("gemini-3.1-pro") // unknown → default, never throws
|
|
64
73
|
})
|
|
65
74
|
|
|
75
|
+
it("mixed tiers price under ONE shared credit family (video-analysis:mixed:*)", () => {
|
|
76
|
+
// Both variants are the identical compute plan — a per-variant price split
|
|
77
|
+
// would be a phantom distinction and double the admin surface.
|
|
78
|
+
for (const bucketSec of VIDEO_ANALYSIS_DURATION_BUCKETS) {
|
|
79
|
+
expect(buildVideoAnalysisCreditId("mixed", bucketSec)).toBe(`video-analysis:mixed:${bucketSec}s`)
|
|
80
|
+
expect(buildVideoAnalysisCreditId("mixed-fast", bucketSec)).toBe(`video-analysis:mixed:${bucketSec}s`)
|
|
81
|
+
const credits = VIDEO_ANALYSIS_BUCKET_CREDITS[`video-analysis:mixed:${bucketSec}s`]
|
|
82
|
+
expect(credits, `missing mixed entry for ${bucketSec}s`).toBeDefined()
|
|
83
|
+
expect(Number.isInteger(credits)).toBe(true)
|
|
84
|
+
// Sanity: mixed (3 fast + 2 pro rolls + refine) must never price below
|
|
85
|
+
// the pro tier it supersets.
|
|
86
|
+
expect(credits).toBeGreaterThanOrEqual(
|
|
87
|
+
VIDEO_ANALYSIS_BUCKET_CREDITS[`video-analysis:gemini-3.1-pro:${bucketSec}s`],
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
66
92
|
// Full drift-detection against the live $-formula lives in
|
|
67
93
|
// backend/src/lib/pricing/__tests__/video-analysis-cost.test.ts (this
|
|
68
94
|
// package cannot see the formula post-S5). This is a lightweight shape
|
package/src/index.ts
CHANGED
|
@@ -255,11 +255,15 @@ export {
|
|
|
255
255
|
VIDEO_ANALYSIS_LLM_MODELS,
|
|
256
256
|
VIDEO_ANALYSIS_TIERS,
|
|
257
257
|
type VideoAnalysisTier,
|
|
258
|
+
type VideoAnalysisModelTier,
|
|
259
|
+
VIDEO_ANALYSIS_MIXED_TIERS,
|
|
260
|
+
type VideoAnalysisMixedTier,
|
|
258
261
|
VIDEO_ANALYSIS_TIER_ORDER,
|
|
259
262
|
DEFAULT_VIDEO_ANALYSIS_TIER,
|
|
260
263
|
DEFAULT_VIDEO_ANALYSIS_MODEL,
|
|
261
264
|
VIDEO_ANALYSIS_TIER_LABELS,
|
|
262
265
|
isVideoAnalysisTier,
|
|
266
|
+
isVideoAnalysisMixedTier,
|
|
263
267
|
resolveVideoAnalysisModel,
|
|
264
268
|
LLM_FEATURE_DEFAULTS,
|
|
265
269
|
LLM_MODALITY_CAPS,
|
package/src/llm-models.ts
CHANGED
|
@@ -396,26 +396,53 @@ export const VIDEO_ANALYSIS_LLM_MODELS: string[] = LLM_MODELS
|
|
|
396
396
|
* so adding a video model forces a tier decision instead of silently leaking.
|
|
397
397
|
*/
|
|
398
398
|
export const VIDEO_ANALYSIS_TIERS = { fast: "gemini-3-flash", pro: "gemini-3.1-pro" } as const
|
|
399
|
-
export type
|
|
399
|
+
export type VideoAnalysisModelTier = keyof typeof VIDEO_ANALYSIS_TIERS
|
|
400
|
+
/**
|
|
401
|
+
* MIXED tiers — advanced multi-engine analysis plans whose identifier resolves
|
|
402
|
+
* to an engine-plan SENTINEL consumed by the analysis engine, never to a single
|
|
403
|
+
* model id. Two variants, same price (one shared `video-analysis:mixed:*`
|
|
404
|
+
* credit family): `mixed` targets maximum result quality; `mixed-fast` targets
|
|
405
|
+
* run-to-run output consistency. What each plan does internally is deliberately
|
|
406
|
+
* NOT published here (Apache irrevocability; only the wire vocabulary below is
|
|
407
|
+
* contract — the engine lives in the private analysis plugin).
|
|
408
|
+
*/
|
|
409
|
+
export const VIDEO_ANALYSIS_MIXED_TIERS = ["mixed", "mixed-fast"] as const
|
|
410
|
+
export type VideoAnalysisMixedTier = (typeof VIDEO_ANALYSIS_MIXED_TIERS)[number]
|
|
400
411
|
/** UI/listing order — recommended (pro) first. */
|
|
401
|
-
export const VIDEO_ANALYSIS_TIER_ORDER = ["pro", "fast"] as const
|
|
412
|
+
export const VIDEO_ANALYSIS_TIER_ORDER = ["pro", "fast", "mixed", "mixed-fast"] as const
|
|
413
|
+
export type VideoAnalysisTier = (typeof VIDEO_ANALYSIS_TIER_ORDER)[number]
|
|
402
414
|
export const DEFAULT_VIDEO_ANALYSIS_TIER: VideoAnalysisTier = "pro"
|
|
403
415
|
export const DEFAULT_VIDEO_ANALYSIS_MODEL: string = VIDEO_ANALYSIS_TIERS[DEFAULT_VIDEO_ANALYSIS_TIER]
|
|
404
416
|
/** Neutral, vendor-free display labels for the UI. */
|
|
405
|
-
export const VIDEO_ANALYSIS_TIER_LABELS: Record<VideoAnalysisTier, string> = {
|
|
417
|
+
export const VIDEO_ANALYSIS_TIER_LABELS: Record<VideoAnalysisTier, string> = {
|
|
418
|
+
fast: "Fast",
|
|
419
|
+
pro: "Pro",
|
|
420
|
+
mixed: "Mixed",
|
|
421
|
+
"mixed-fast": "Mixed (consistent)",
|
|
422
|
+
}
|
|
406
423
|
|
|
407
424
|
export function isVideoAnalysisTier(v: string): v is VideoAnalysisTier {
|
|
408
|
-
return
|
|
425
|
+
return (VIDEO_ANALYSIS_TIER_ORDER as readonly string[]).includes(v)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export function isVideoAnalysisMixedTier(v: string): v is VideoAnalysisMixedTier {
|
|
429
|
+
return (VIDEO_ANALYSIS_MIXED_TIERS as readonly string[]).includes(v)
|
|
409
430
|
}
|
|
410
431
|
|
|
411
432
|
/**
|
|
412
|
-
* Resolve a user-supplied tier
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
433
|
+
* Resolve a user-supplied tier OR a raw internal model id to the analysis
|
|
434
|
+
* ENGINE IDENTIFIER carried in the worker payload:
|
|
435
|
+
* - model-backed tiers ("fast"/"pro") → the internal model id;
|
|
436
|
+
* - mixed tiers ("mixed"/"mixed-fast") → the sentinel ITSELF (the engine
|
|
437
|
+
* expands it to a multi-model roll plan);
|
|
438
|
+
* - raw model ids pass through (back-compat for stored `llmModel` values);
|
|
439
|
+
* - empty/unknown → the default tier's model (never an error).
|
|
416
440
|
*/
|
|
417
441
|
export function resolveVideoAnalysisModel(input?: string | null): string {
|
|
418
|
-
if (input &&
|
|
442
|
+
if (input && isVideoAnalysisMixedTier(input)) return input
|
|
443
|
+
if (input && Object.prototype.hasOwnProperty.call(VIDEO_ANALYSIS_TIERS, input)) {
|
|
444
|
+
return VIDEO_ANALYSIS_TIERS[input as VideoAnalysisModelTier]
|
|
445
|
+
}
|
|
419
446
|
if (input && VIDEO_ANALYSIS_LLM_MODELS.includes(input)) return input
|
|
420
447
|
return DEFAULT_VIDEO_ANALYSIS_MODEL
|
|
421
448
|
}
|
package/src/model-catalog.ts
CHANGED
|
@@ -1839,6 +1839,26 @@ const VIDEO_MODELS: Record<string, ModelCatalogEntry> = {
|
|
|
1839
1839
|
{ identifier: "video-analysis:gemini-3.1-pro:600s", credits: 11, note: "10-min ceiling" },
|
|
1840
1840
|
],
|
|
1841
1841
|
},
|
|
1842
|
+
// Both mixed tiers are variants of the same advanced multi-engine analysis
|
|
1843
|
+
// and share this ONE credit family (videoAnalysisCreditSegment maps both;
|
|
1844
|
+
// plan internals live in the private analysis plugin).
|
|
1845
|
+
"mixed-video-analysis": {
|
|
1846
|
+
id: "mixed-video-analysis",
|
|
1847
|
+
kind: "video",
|
|
1848
|
+
modes: ["video-analysis"] as const,
|
|
1849
|
+
family: "Nodaro",
|
|
1850
|
+
label: "Video Analysis (Mixed)",
|
|
1851
|
+
series: "Video Analysis",
|
|
1852
|
+
description: "Our most advanced analysis tier — multiple analysis engines combined into one result for maximum completeness and accuracy. Billed per duration bucket.",
|
|
1853
|
+
useCases: ["video-analysis", "shot-list", "premium", "most-complete"],
|
|
1854
|
+
pricing: [
|
|
1855
|
+
{ identifier: "video-analysis:mixed", credits: 14, note: "10-min ceiling (no duration given)" },
|
|
1856
|
+
{ identifier: "video-analysis:mixed:60s", credits: 3 },
|
|
1857
|
+
{ identifier: "video-analysis:mixed:180s", credits: 4 },
|
|
1858
|
+
{ identifier: "video-analysis:mixed:360s", credits: 9 },
|
|
1859
|
+
{ identifier: "video-analysis:mixed:600s", credits: 14, note: "10-min ceiling" },
|
|
1860
|
+
],
|
|
1861
|
+
},
|
|
1842
1862
|
}
|
|
1843
1863
|
|
|
1844
1864
|
// =============================================================================
|
|
@@ -54,6 +54,24 @@ export const VIDEO_ANALYSIS_BUCKET_CREDITS: Record<string, number> = {
|
|
|
54
54
|
"video-analysis:gemini-3.1-pro:180s": 3,
|
|
55
55
|
"video-analysis:gemini-3.1-pro:360s": 7,
|
|
56
56
|
"video-analysis:gemini-3.1-pro:600s": 11,
|
|
57
|
+
// Mixed tiers (`mixed` + `mixed-fast`) share ONE credit family — they are
|
|
58
|
+
// variants of the same engine plan (plan internals live in the private
|
|
59
|
+
// analysis plugin). Admin-tunable via model_pricing like every other row.
|
|
60
|
+
"video-analysis:mixed:60s": 3,
|
|
61
|
+
"video-analysis:mixed:180s": 4,
|
|
62
|
+
"video-analysis:mixed:360s": 9,
|
|
63
|
+
"video-analysis:mixed:600s": 14,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The credit-id MODEL SEGMENT for an engine identifier: both mixed-tier
|
|
68
|
+
* sentinels share the `mixed` price family (same engine plan); everything
|
|
69
|
+
* else prices under its own identifier. Single source of truth — used by
|
|
70
|
+
* `buildVideoAnalysisCreditId` below, so route/orchestrator/UI callers can
|
|
71
|
+
* never diverge on where a sentinel prices.
|
|
72
|
+
*/
|
|
73
|
+
export function videoAnalysisCreditSegment(modelOrSentinel: string): string {
|
|
74
|
+
return modelOrSentinel === "mixed-fast" ? "mixed" : modelOrSentinel
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
export function pickVideoAnalysisBucket(durationSec: number): number {
|
|
@@ -65,7 +83,7 @@ export function buildVideoAnalysisCreditId(model: string, durationSec?: number):
|
|
|
65
83
|
const bucket = durationSec !== undefined && durationSec > 0
|
|
66
84
|
? pickVideoAnalysisBucket(Math.min(durationSec, VIDEO_ANALYSIS_MAX_DURATION_SEC))
|
|
67
85
|
: VIDEO_ANALYSIS_MAX_DURATION_SEC // unknown → ceiling composite (the ONLY silent-ceiling path)
|
|
68
|
-
return `video-analysis:${model}:${bucket}s`
|
|
86
|
+
return `video-analysis:${videoAnalysisCreditSegment(model)}:${bucket}s`
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
export function bucketSecondsFromCreditId(creditId: string): number | null {
|