1
>
/*---------------------------------------------------------------------------------------------
agentModelPricing.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import type { SessionModelInfo } from './state/protocol/state.js';
7
>
import type { IAgentModelInfo } from './agentService.js';
8
>
9
>
/**
10
>
* Well-known model picker metadata carried under a model's open `_meta` bag (see {@link IAgentModelInfo._meta} /
11
>
* {@link SessionModelInfo._meta}). Agents populate these keys so the chat model picker can render pricing,
12
>
* capability categories, and promotions.
13
>
*
14
>
* All cost values are expressed as credits per 1M tokens — the same unit the model picker hover renders (see
15
>
* `getModelHoverContent` in `modelPicker/modelPickerHover.ts`). Fields are optional; agents omit what they don't know.
16
>
*/
17
>
export interface IAgentModelPricingMeta {
18
>
/** Request multiplier (e.g. `1.5` rendered as "1.5x"). */
19
>
readonly multiplierNumeric?: number;
20
>
/** Default-tier input cost in credits per 1M tokens. */
21
>
readonly inputCost?: number;
22
>
/** Default-tier cached-input (read) cost in credits per 1M tokens. */
23
>
readonly cacheCost?: number;
24
>
/** Default-tier cache-write cost in credits per 1M tokens. */
25
>
readonly cacheWriteCost?: number;
26
>
/** Default-tier output cost in credits per 1M tokens. */
27
>
readonly outputCost?: number;
28
>
/** Long-context-tier input cost in credits per 1M tokens. */
29
>
readonly longContextInputCost?: number;
30
>
/** Long-context-tier cached-input (read) cost in credits per 1M tokens. */
31
>
readonly longContextCacheCost?: number;
32
>
/** Long-context-tier cache-write cost in credits per 1M tokens. */
33
>
readonly longContextCacheWriteCost?: number;
34
>
/** Long-context-tier output cost in credits per 1M tokens. */
35
>
readonly longContextOutputCost?: number;
36
>
/** Coarse price bucket (e.g. `low`, `medium`, `high`) for an at-a-glance tag. */
37
>
readonly priceCategory?: string;
38
>
/** Capability category (e.g. `lightweight`, `versatile`, `powerful`) shown in the model picker hover. */
39
>
readonly category?: string;
40
>
/** Whole-number percentage discount (0-100) for the synthetic `auto` model; shown as a "{n}% discount" detail. */
41
>
readonly discountPercent?: number;
42
>
/** Promotional information when the model is experiencing a discount. */
43
>
readonly promo?: {
44
>
readonly id: string;
45
>
readonly discountPercent: number;
46
>
readonly endsAt: string;
47
>
readonly message: string;
48
>
};
49
>
}
50
>
51
>
const NUMBER_KEYS = [
52
>
'multiplierNumeric',
53
>
'inputCost',
54
>
'cacheCost',
55
>
'cacheWriteCost',
56
>
'outputCost',
57
>
'longContextInputCost',
58
>
'longContextCacheCost',
59
>
'longContextCacheWriteCost',
60
>
'longContextOutputCost',
61
>
'discountPercent',
62
>
] as const satisfies readonly (keyof IAgentModelPricingMeta)[];
63
>
64
>
/**
65
>
* Reads the well-known {@link IAgentModelPricingMeta} keys from a model's open `_meta` bag, ignoring any unrelated
66
>
* provider-specific keys and values of the wrong type. Returns an object containing only the keys that were present
67
>
* with a valid value.
68
>
*/
69
>
export function readAgentModelPricingMeta(model: IAgentModelInfo | SessionModelInfo): IAgentModelPricingMeta {
70
const meta = model._meta;
71
if (!meta) {