@applica-software-guru/persona-sdk 0.1.114 → 0.1.115
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/README.md +86 -1
- package/dist/bundle.cjs.js +1 -1
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +203 -92
- package/dist/bundle.es.js.map +1 -1
- package/dist/index.d.ts +264 -3
- package/package.json +1 -1
- package/src/agents/types.ts +6 -2
- package/src/billing/billing-client.ts +3 -0
- package/src/billing/types.ts +16 -0
- package/src/index.ts +21 -0
- package/src/model-aliases/model-aliases-api.ts +94 -0
- package/src/model-aliases/references.ts +20 -0
- package/src/model-aliases/types.ts +125 -0
- package/src/notifications/notifications-api.ts +42 -0
- package/src/notifications/types.ts +39 -0
- package/src/persona-sdk.ts +14 -0
- package/src/sessions/types.ts +2 -0
- package/tests/billing-aliases.test.mjs +71 -0
- package/tests/model-aliases-api.test.mjs +198 -0
- package/tests/notifications-api.test.mjs +88 -0
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,45 @@ export declare interface AgentValue {
|
|
|
117
117
|
initialContext?: Record<string, unknown>;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/** Prefix of a model name that references a model alias. */
|
|
121
|
+
export declare const ALIAS_PREFIX = "alias:";
|
|
122
|
+
|
|
123
|
+
/** Agents referencing an alias; also the detail of the 409 returned when deleting one in use. */
|
|
124
|
+
export declare interface AliasImpact {
|
|
125
|
+
aliasId: string;
|
|
126
|
+
aliasName: string;
|
|
127
|
+
/** May exceed `usages.length` when the list is capped. */
|
|
128
|
+
total: number;
|
|
129
|
+
usages: AliasUsage[];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** `"alias:smart"` -> `"smart"`. Throws when `modelName` is not a reference. */
|
|
133
|
+
export declare function aliasNameFromRef(modelName: string): string;
|
|
134
|
+
|
|
135
|
+
/** `"smart"` -> `"alias:smart"`, to set as the `modelName` of an agent. */
|
|
136
|
+
export declare function aliasRef(name: string): string;
|
|
137
|
+
|
|
138
|
+
/** A proposal only: nothing is applied, the alias is edited by hand. */
|
|
139
|
+
export declare interface AliasSuggestions {
|
|
140
|
+
aliasId?: string | null;
|
|
141
|
+
/** The model the suggestions are measured against (the alias' target by default). */
|
|
142
|
+
referenceModel: string;
|
|
143
|
+
/** null when the registry does not know the reference model (e.g. already retired). */
|
|
144
|
+
reference?: ModelProfile | null;
|
|
145
|
+
notes: string[];
|
|
146
|
+
replacements: ModelSuggestion[];
|
|
147
|
+
fallbacks: ModelSuggestion[];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** An agent that references an alias, and in which model slots. */
|
|
151
|
+
export declare interface AliasUsage {
|
|
152
|
+
agentId: string;
|
|
153
|
+
agentName?: string | null;
|
|
154
|
+
projectId?: string | null;
|
|
155
|
+
/** `model`, `compaction`, `loopRecovery`, `attachmentsPreprocessor`, `knowledge`. */
|
|
156
|
+
usedIn: string[];
|
|
157
|
+
}
|
|
158
|
+
|
|
120
159
|
export declare class ApiException extends Error {
|
|
121
160
|
readonly statusCode: number;
|
|
122
161
|
readonly body: string;
|
|
@@ -246,7 +285,7 @@ export declare class BillingClient {
|
|
|
246
285
|
listInvoices(owner: string, dateFrom?: string, dateTo?: string): Promise<Invoice[]>;
|
|
247
286
|
cancelSubscription(owner: string): Promise<Subscription>;
|
|
248
287
|
getUsageStats(projectId: string, dateFrom?: string, dateTo?: string, models?: string[]): Promise<UsageStats>;
|
|
249
|
-
listUsages(projectId: string, dateFrom?: string, dateTo?: string, models?: string[], sessionId?: string, page?: number, size?: number): Promise<UsagePage>;
|
|
288
|
+
listUsages(projectId: string, dateFrom?: string, dateTo?: string, models?: string[], sessionId?: string, page?: number, size?: number, aliases?: string[]): Promise<UsagePage>;
|
|
250
289
|
}
|
|
251
290
|
|
|
252
291
|
export declare interface BillingUsage {
|
|
@@ -670,6 +709,9 @@ export declare interface Invoice {
|
|
|
670
709
|
lines?: LineItem[];
|
|
671
710
|
}
|
|
672
711
|
|
|
712
|
+
/** True when `modelName` is an `alias:<name>` reference. */
|
|
713
|
+
export declare function isAliasRef(modelName?: string | null): boolean;
|
|
714
|
+
|
|
673
715
|
export declare interface KnowledgeBase {
|
|
674
716
|
id?: string;
|
|
675
717
|
projectId?: string;
|
|
@@ -876,8 +918,131 @@ export declare class MissionsApi extends HttpApi {
|
|
|
876
918
|
|
|
877
919
|
export declare type MissionStatus = 'draft' | 'planned' | 'active' | 'review' | 'paused' | 'completed' | 'failed' | 'cancelled';
|
|
878
920
|
|
|
921
|
+
/**
|
|
922
|
+
* A named indirection to a concrete `<provider>/<model>`. An agent references it as
|
|
923
|
+
* `alias:<name>` (see {@link aliasRef}); editing the alias moves every agent using it.
|
|
924
|
+
*/
|
|
925
|
+
export declare interface ModelAlias {
|
|
926
|
+
id: string;
|
|
927
|
+
/** Lowercase slug used in `alias:<name>`. Immutable. */
|
|
928
|
+
name: string;
|
|
929
|
+
/** null => global (super admins only); set => per-project. Immutable. */
|
|
930
|
+
projectId?: string | null;
|
|
931
|
+
description?: string | null;
|
|
932
|
+
/** Concrete litellm-style `<provider>/<model>`, never another alias. */
|
|
933
|
+
target: string;
|
|
934
|
+
/** Ordered alternatives, used at runtime when the target cannot serve a call. */
|
|
935
|
+
fallbacks: string[];
|
|
936
|
+
defaults: ModelAliasDefaults;
|
|
937
|
+
/** Result of the last health check. Managed by the server. */
|
|
938
|
+
health: ModelAliasHealth;
|
|
939
|
+
/** Managed by the server. */
|
|
940
|
+
history: ModelAliasChange[];
|
|
941
|
+
createdAt?: string;
|
|
942
|
+
updatedAt?: string;
|
|
943
|
+
updatedBy?: string | null;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/** Audit entry: one changed field of the alias (the last 50 are kept). */
|
|
947
|
+
export declare interface ModelAliasChange {
|
|
948
|
+
at: string;
|
|
949
|
+
by?: string | null;
|
|
950
|
+
field: 'target' | 'fallbacks' | 'defaults';
|
|
951
|
+
old?: unknown;
|
|
952
|
+
new?: unknown;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** Applied only to the fields an agent leaves empty. `temperature` is not here on purpose. */
|
|
956
|
+
export declare interface ModelAliasDefaults {
|
|
957
|
+
reasoningEffort?: ReasoningEffort | null;
|
|
958
|
+
maxOutputTokens?: number | null;
|
|
959
|
+
contextWindow?: number | null;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Model aliases: named indirections (`alias:<name>`) to a concrete model, with
|
|
964
|
+
* ordered fallbacks. Global aliases are managed by super admins; project aliases by
|
|
965
|
+
* super admins, project admins and the project API key (not plain users, nor agent
|
|
966
|
+
* keys). Everyone in a project can read its aliases and the global ones.
|
|
967
|
+
*/
|
|
968
|
+
export declare class ModelAliasesApi extends HttpApi {
|
|
969
|
+
constructor(baseUrl: string, auth: string | AuthenticationProvider);
|
|
970
|
+
/**
|
|
971
|
+
* Aliases visible to the caller (their project's and the global ones). Super admins
|
|
972
|
+
* can pass `projectId` to see another project's view.
|
|
973
|
+
*/
|
|
974
|
+
list(projectId?: string | null, keyword?: string | null, page?: number, size?: number): Promise<Paginated<ModelAlias>>;
|
|
975
|
+
get(id: string): Promise<ModelAlias>;
|
|
976
|
+
/** Create an alias. Non-super-admins always create in their own project. */
|
|
977
|
+
create(alias: ModelAliasInput): Promise<ModelAlias>;
|
|
978
|
+
/** Change target, fallbacks, defaults and description. `name` and the scope are immutable. */
|
|
979
|
+
update(id: string, alias: ModelAliasInput): Promise<ModelAlias>;
|
|
980
|
+
/**
|
|
981
|
+
* Delete an alias. Refused with a 409 while agents still reference it: use
|
|
982
|
+
* {@link ModelAliasesApi.inUse} on the error to read which ones.
|
|
983
|
+
*/
|
|
984
|
+
remove(id: string): Promise<void>;
|
|
985
|
+
/** Agents that reference the alias, and in which model slot. */
|
|
986
|
+
impact(id: string): Promise<AliasImpact>;
|
|
987
|
+
/**
|
|
988
|
+
* Run the health check now (registry, announced retirements, credentials). Stores the
|
|
989
|
+
* result in `health` and updates the notifications; it never changes the alias.
|
|
990
|
+
*/
|
|
991
|
+
check(id: string): Promise<ModelAlias>;
|
|
992
|
+
/**
|
|
993
|
+
* Replacement and fallback candidates for the alias' target, or for `model` (e.g. a
|
|
994
|
+
* fallback that went missing). A proposal only: nothing is applied.
|
|
995
|
+
*/
|
|
996
|
+
suggestions(id: string, model?: string | null, limit?: number): Promise<AliasSuggestions>;
|
|
997
|
+
/**
|
|
998
|
+
* The agents blocking a delete, when `error` is the 409 of {@link ModelAliasesApi.remove};
|
|
999
|
+
* `null` for any other error.
|
|
1000
|
+
*/
|
|
1001
|
+
static inUse(error: unknown): AliasImpact | null;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
export declare interface ModelAliasHealth {
|
|
1005
|
+
status: ModelAliasHealthStatus;
|
|
1006
|
+
checkedAt?: string | null;
|
|
1007
|
+
issues: ModelAliasIssue[];
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
export declare type ModelAliasHealthStatus = 'unknown' | 'ok' | 'deprecating' | 'missing' | 'no_credentials';
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* What to send to create or update an alias. The server-managed fields (`health`,
|
|
1014
|
+
* `history`, timestamps) are not part of it; `name` is required but immutable, and
|
|
1015
|
+
* the scope can only be chosen (via `projectId`) by super admins when creating.
|
|
1016
|
+
*/
|
|
1017
|
+
export declare interface ModelAliasInput {
|
|
1018
|
+
name: string;
|
|
1019
|
+
target: string;
|
|
1020
|
+
projectId?: string | null;
|
|
1021
|
+
description?: string | null;
|
|
1022
|
+
fallbacks?: string[];
|
|
1023
|
+
defaults?: ModelAliasDefaults;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** A problem found by the health check on one of the alias' models. */
|
|
1027
|
+
export declare interface ModelAliasIssue {
|
|
1028
|
+
model: string;
|
|
1029
|
+
role: ModelAliasIssueRole;
|
|
1030
|
+
status: ModelAliasHealthStatus;
|
|
1031
|
+
detail?: string | null;
|
|
1032
|
+
/** Provider-announced retirement date (`YYYY-MM-DD`), when known. */
|
|
1033
|
+
deprecationDate?: string | null;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
export declare type ModelAliasIssueRole = 'target' | 'fallback';
|
|
1037
|
+
|
|
1038
|
+
export declare type ModelCapability = 'function_calling' | 'vision' | 'audio_input' | 'pdf_input' | 'reasoning';
|
|
1039
|
+
|
|
879
1040
|
export declare interface ModelConfiguration {
|
|
880
|
-
/**
|
|
1041
|
+
/**
|
|
1042
|
+
* litellm-style "<provider>/<model>" string (e.g. "fireworks/accounts/fireworks/models/minimax-m3"), or a
|
|
1043
|
+
* model alias reference "alias:<name>" (see `aliasRef`), resolved by the server. Use the known-models API
|
|
1044
|
+
* for the current list.
|
|
1045
|
+
*/
|
|
881
1046
|
modelName?: string;
|
|
882
1047
|
temperature?: number;
|
|
883
1048
|
reasoningEffort?: ReasoningEffort;
|
|
@@ -903,8 +1068,26 @@ export declare interface ModelConfiguration {
|
|
|
903
1068
|
openrouterModelName?: string;
|
|
904
1069
|
}
|
|
905
1070
|
|
|
1071
|
+
/** What litellm's registry knows about a model. */
|
|
1072
|
+
export declare interface ModelProfile {
|
|
1073
|
+
model: string;
|
|
1074
|
+
contextWindow?: number | null;
|
|
1075
|
+
/** USD per million tokens. */
|
|
1076
|
+
inputCostPerMillion?: number | null;
|
|
1077
|
+
outputCostPerMillion?: number | null;
|
|
1078
|
+
capabilities: ModelCapability[];
|
|
1079
|
+
}
|
|
1080
|
+
|
|
906
1081
|
export declare type ModelProvider = 'google' | 'openai' | 'grok' | 'fireworks' | 'together' | 'ollama' | 'openai_compatible' | 'openrouter';
|
|
907
1082
|
|
|
1083
|
+
/** A candidate to replace a model, or to add as a fallback. */
|
|
1084
|
+
export declare interface ModelSuggestion extends ModelProfile {
|
|
1085
|
+
provider: string;
|
|
1086
|
+
sameProvider: boolean;
|
|
1087
|
+
/** e.g. a smaller context window, a much higher price. */
|
|
1088
|
+
warnings: string[];
|
|
1089
|
+
}
|
|
1090
|
+
|
|
908
1091
|
export declare interface NetworkConfiguration {
|
|
909
1092
|
allowedWebsites?: string[];
|
|
910
1093
|
allowedIps?: string[];
|
|
@@ -934,6 +1117,34 @@ export declare interface NodeExecutionResult {
|
|
|
934
1117
|
|
|
935
1118
|
export declare type NodeType = 'start' | 'action' | 'condition' | 'loop' | 'tool' | 'agent' | 'set_var' | 'output' | 'workflow' | 'resource' | 'script';
|
|
936
1119
|
|
|
1120
|
+
/**
|
|
1121
|
+
* An in-platform notification (badge + banner). `title` and `message` are an English
|
|
1122
|
+
* fallback: clients localize from `code` and `data`.
|
|
1123
|
+
*/
|
|
1124
|
+
declare interface Notification_2 {
|
|
1125
|
+
id: string;
|
|
1126
|
+
/** null => platform-wide, visible to super admins only. */
|
|
1127
|
+
projectId?: string | null;
|
|
1128
|
+
/** Producer area, e.g. `model_alias`. */
|
|
1129
|
+
type: string;
|
|
1130
|
+
/** Stable machine code, e.g. `model_alias.missing`, `model_alias.runtime_fallback`. */
|
|
1131
|
+
code: string;
|
|
1132
|
+
severity: NotificationSeverity;
|
|
1133
|
+
title: string;
|
|
1134
|
+
message: string;
|
|
1135
|
+
/** What it is about, for deep links. */
|
|
1136
|
+
entityType?: string | null;
|
|
1137
|
+
entityId?: string | null;
|
|
1138
|
+
dedupeKey?: string | null;
|
|
1139
|
+
data: Record<string, unknown>;
|
|
1140
|
+
createdAt?: string;
|
|
1141
|
+
readAt?: string | null;
|
|
1142
|
+
readBy?: string | null;
|
|
1143
|
+
/** Set when the problem it describes no longer applies. */
|
|
1144
|
+
resolvedAt?: string | null;
|
|
1145
|
+
}
|
|
1146
|
+
export { Notification_2 as Notification }
|
|
1147
|
+
|
|
937
1148
|
/** A place where a project's human tasks are announced (e.g. a Telegram group). */
|
|
938
1149
|
export declare interface NotificationChannel {
|
|
939
1150
|
id: string;
|
|
@@ -951,6 +1162,34 @@ export declare interface NotificationChannel {
|
|
|
951
1162
|
updatedAt?: string;
|
|
952
1163
|
}
|
|
953
1164
|
|
|
1165
|
+
export declare interface NotificationListParams {
|
|
1166
|
+
/** Only the ones not read yet. */
|
|
1167
|
+
unreadOnly?: boolean;
|
|
1168
|
+
/** Include the ones whose problem is gone (hidden by default). */
|
|
1169
|
+
includeResolved?: boolean;
|
|
1170
|
+
/** Super admins: the view of this project (plus platform-wide ones). */
|
|
1171
|
+
projectId?: string | null;
|
|
1172
|
+
page?: number;
|
|
1173
|
+
size?: number;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* In-platform notifications. A project sees its own; platform-wide ones (no project)
|
|
1178
|
+
* are for super admins. Agent API keys have no access. Read state is shared by
|
|
1179
|
+
* everyone who can see a notification.
|
|
1180
|
+
*/
|
|
1181
|
+
export declare class NotificationsApi extends HttpApi {
|
|
1182
|
+
constructor(baseUrl: string, auth: string | AuthenticationProvider);
|
|
1183
|
+
list(params?: NotificationListParams): Promise<Paginated<Notification_2>>;
|
|
1184
|
+
/** Open, unread notifications: the value of the badge. */
|
|
1185
|
+
unreadCount(projectId?: string | null): Promise<number>;
|
|
1186
|
+
markRead(id: string): Promise<Notification_2>;
|
|
1187
|
+
/** Mark as read everything the caller can see. */
|
|
1188
|
+
markAllRead(projectId?: string | null): Promise<void>;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export declare type NotificationSeverity = 'info' | 'warning' | 'critical';
|
|
1192
|
+
|
|
954
1193
|
export declare interface OAuth2CallbackResponse {
|
|
955
1194
|
id?: string;
|
|
956
1195
|
successUrl?: string;
|
|
@@ -1038,6 +1277,10 @@ export declare class PersonaSdk {
|
|
|
1038
1277
|
missions(authProvider: AuthenticationProvider): MissionsApi;
|
|
1039
1278
|
billing(apiKey: string): BillingClient;
|
|
1040
1279
|
billing(authProvider: AuthenticationProvider): BillingClient;
|
|
1280
|
+
modelAliases(apiKey: string): ModelAliasesApi;
|
|
1281
|
+
modelAliases(authProvider: AuthenticationProvider): ModelAliasesApi;
|
|
1282
|
+
notifications(apiKey: string): NotificationsApi;
|
|
1283
|
+
notifications(authProvider: AuthenticationProvider): NotificationsApi;
|
|
1041
1284
|
values(apiKey: string): ValuesApi;
|
|
1042
1285
|
values(authProvider: AuthenticationProvider): ValuesApi;
|
|
1043
1286
|
}
|
|
@@ -1150,7 +1393,7 @@ export declare class ProvidersApi extends HttpApi {
|
|
|
1150
1393
|
models(provider: string): Promise<ProviderModel[]>;
|
|
1151
1394
|
}
|
|
1152
1395
|
|
|
1153
|
-
export declare type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
|
|
1396
|
+
export declare type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
1154
1397
|
|
|
1155
1398
|
export declare interface Ref {
|
|
1156
1399
|
nodeId?: string;
|
|
@@ -1570,6 +1813,18 @@ export declare interface UpgradeSubscriptionRequest {
|
|
|
1570
1813
|
toPlanType: string;
|
|
1571
1814
|
}
|
|
1572
1815
|
|
|
1816
|
+
/**
|
|
1817
|
+
* Usage that went through a model alias. The cost is the sum over every concrete model
|
|
1818
|
+
* the alias served, so it follows the alias even when its target changes.
|
|
1819
|
+
*/
|
|
1820
|
+
export declare interface UsageAliasEntry {
|
|
1821
|
+
alias: string;
|
|
1822
|
+
credits: number;
|
|
1823
|
+
count: number;
|
|
1824
|
+
totalCost?: number;
|
|
1825
|
+
totalPrice?: number;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1573
1828
|
export declare interface UsageCost {
|
|
1574
1829
|
service?: string;
|
|
1575
1830
|
value?: number;
|
|
@@ -1577,6 +1832,8 @@ export declare interface UsageCost {
|
|
|
1577
1832
|
price?: number;
|
|
1578
1833
|
credits?: number;
|
|
1579
1834
|
unit?: string;
|
|
1835
|
+
/** Name of the model alias the usage went through, if any. `service` names the concrete model that served it. */
|
|
1836
|
+
alias?: string | null;
|
|
1580
1837
|
}
|
|
1581
1838
|
|
|
1582
1839
|
export declare interface UsageDailyEntry {
|
|
@@ -1594,6 +1851,8 @@ export declare interface UsageDetail {
|
|
|
1594
1851
|
price?: number;
|
|
1595
1852
|
credits?: number;
|
|
1596
1853
|
unit?: string;
|
|
1854
|
+
/** Name of the model alias the usage went through, if any. `service` names the concrete model that served it. */
|
|
1855
|
+
alias?: string | null;
|
|
1597
1856
|
[key: string]: unknown;
|
|
1598
1857
|
}
|
|
1599
1858
|
|
|
@@ -1618,6 +1877,8 @@ export declare interface UsageStats {
|
|
|
1618
1877
|
totals: UsageTotals;
|
|
1619
1878
|
daily: UsageDailyEntry[];
|
|
1620
1879
|
byModel: UsageModelEntry[];
|
|
1880
|
+
/** Breakdown by model alias; empty (or absent on an older billing service) when none was used. */
|
|
1881
|
+
byAlias?: UsageAliasEntry[];
|
|
1621
1882
|
availableModels: string[];
|
|
1622
1883
|
hasCostData?: boolean;
|
|
1623
1884
|
costDataMode?: 'actual' | 'estimated_price' | 'mixed' | 'none';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@applica-software-guru/persona-sdk",
|
|
3
3
|
"description": "Official TypeScript SDK for the Persona API — manage agents, sessions, projects, knowledge bases, workflows, triggers and more.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.115",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "vite",
|
package/src/agents/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type ToolType = 'remote' | 'local';
|
|
|
15
15
|
|
|
16
16
|
export type CollaborationMode = 'delegate_and_return' | 'persistent_transfer' | 'consult_then_respond';
|
|
17
17
|
|
|
18
|
-
export type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
|
|
18
|
+
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
19
19
|
|
|
20
20
|
export type ModelProvider = 'google' | 'openai' | 'grok' | 'fireworks' | 'together' | 'ollama' | 'openai_compatible' | 'openrouter';
|
|
21
21
|
|
|
@@ -37,7 +37,11 @@ export interface Variable {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface ModelConfiguration {
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* litellm-style "<provider>/<model>" string (e.g. "fireworks/accounts/fireworks/models/minimax-m3"), or a
|
|
42
|
+
* model alias reference "alias:<name>" (see `aliasRef`), resolved by the server. Use the known-models API
|
|
43
|
+
* for the current list.
|
|
44
|
+
*/
|
|
41
45
|
modelName?: string;
|
|
42
46
|
temperature?: number;
|
|
43
47
|
reasoningEffort?: ReasoningEffort;
|
|
@@ -168,6 +168,7 @@ export class BillingClient {
|
|
|
168
168
|
sessionId?: string,
|
|
169
169
|
page?: number,
|
|
170
170
|
size?: number,
|
|
171
|
+
aliases?: string[],
|
|
171
172
|
): Promise<UsagePage> {
|
|
172
173
|
const params: string[] = [];
|
|
173
174
|
if (dateFrom) params.push('date_from=' + encodeURIComponent(dateFrom));
|
|
@@ -176,6 +177,8 @@ export class BillingClient {
|
|
|
176
177
|
if (sessionId) params.push('session_id=' + encodeURIComponent(sessionId));
|
|
177
178
|
if (page !== undefined) params.push('page=' + encodeURIComponent(String(page)));
|
|
178
179
|
if (size !== undefined) params.push('size=' + encodeURIComponent(String(size)));
|
|
180
|
+
// usages with at least one line that went through one of these aliases
|
|
181
|
+
if (aliases?.length) aliases.forEach(a => params.push('alias=' + encodeURIComponent(a)));
|
|
179
182
|
const query = params.length > 0 ? '?' + params.join('&') : '';
|
|
180
183
|
return this.request<UsagePage>('/projects/' + projectId + '/subscription/usages' + query, 'GET');
|
|
181
184
|
}
|
package/src/billing/types.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface UsageDetail {
|
|
|
72
72
|
price?: number;
|
|
73
73
|
credits?: number;
|
|
74
74
|
unit?: string;
|
|
75
|
+
/** Name of the model alias the usage went through, if any. `service` names the concrete model that served it. */
|
|
76
|
+
alias?: string | null;
|
|
75
77
|
[key: string]: unknown;
|
|
76
78
|
}
|
|
77
79
|
|
|
@@ -142,6 +144,18 @@ export interface UsageModelEntry {
|
|
|
142
144
|
totalPrice?: number;
|
|
143
145
|
}
|
|
144
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Usage that went through a model alias. The cost is the sum over every concrete model
|
|
149
|
+
* the alias served, so it follows the alias even when its target changes.
|
|
150
|
+
*/
|
|
151
|
+
export interface UsageAliasEntry {
|
|
152
|
+
alias: string;
|
|
153
|
+
credits: number;
|
|
154
|
+
count: number;
|
|
155
|
+
totalCost?: number;
|
|
156
|
+
totalPrice?: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
145
159
|
export interface UsageTotals {
|
|
146
160
|
creditsUsed: number;
|
|
147
161
|
usageCount: number;
|
|
@@ -157,6 +171,8 @@ export interface UsageStats {
|
|
|
157
171
|
totals: UsageTotals;
|
|
158
172
|
daily: UsageDailyEntry[];
|
|
159
173
|
byModel: UsageModelEntry[];
|
|
174
|
+
/** Breakdown by model alias; empty (or absent on an older billing service) when none was used. */
|
|
175
|
+
byAlias?: UsageAliasEntry[];
|
|
160
176
|
availableModels: string[];
|
|
161
177
|
hasCostData?: boolean;
|
|
162
178
|
costDataMode?: 'actual' | 'estimated_price' | 'mixed' | 'none';
|
package/src/index.ts
CHANGED
|
@@ -180,6 +180,26 @@ export { MarkupRulesApi } from './markup-rules/markup-rules-api';
|
|
|
180
180
|
export type { MarkupRule } from './markup-rules/types';
|
|
181
181
|
export { ProvidersApi } from './providers/providers-api';
|
|
182
182
|
export type { Provider, ProviderModel } from './providers/types';
|
|
183
|
+
export { ModelAliasesApi } from './model-aliases/model-aliases-api';
|
|
184
|
+
export { ALIAS_PREFIX, isAliasRef, aliasNameFromRef, aliasRef } from './model-aliases/references';
|
|
185
|
+
export type {
|
|
186
|
+
ModelAlias,
|
|
187
|
+
ModelAliasInput,
|
|
188
|
+
ModelAliasDefaults,
|
|
189
|
+
ModelAliasHealth,
|
|
190
|
+
ModelAliasHealthStatus,
|
|
191
|
+
ModelAliasIssue,
|
|
192
|
+
ModelAliasIssueRole,
|
|
193
|
+
ModelAliasChange,
|
|
194
|
+
AliasImpact,
|
|
195
|
+
AliasUsage,
|
|
196
|
+
AliasSuggestions,
|
|
197
|
+
ModelSuggestion,
|
|
198
|
+
ModelProfile,
|
|
199
|
+
ModelCapability,
|
|
200
|
+
} from './model-aliases/types';
|
|
201
|
+
export { NotificationsApi } from './notifications/notifications-api';
|
|
202
|
+
export type { Notification, NotificationSeverity, NotificationListParams } from './notifications/types';
|
|
183
203
|
export type { Revision as RevisionType } from './revisions/types';
|
|
184
204
|
export { BillingClient } from './billing/billing-client';
|
|
185
205
|
export { ValuesApi } from './values/values-api';
|
|
@@ -200,6 +220,7 @@ export type {
|
|
|
200
220
|
UsageTotals,
|
|
201
221
|
UsageDailyEntry,
|
|
202
222
|
UsageModelEntry,
|
|
223
|
+
UsageAliasEntry,
|
|
203
224
|
UsageDetail,
|
|
204
225
|
UsagePage,
|
|
205
226
|
} from './billing/types';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { HttpApi } from '../http-api';
|
|
2
|
+
import { Paginated } from '../paginated';
|
|
3
|
+
import { AuthenticationProvider } from '../auth/authentication-provider';
|
|
4
|
+
import { ApiException } from '../exceptions';
|
|
5
|
+
import { AliasImpact, AliasSuggestions, ModelAlias, ModelAliasInput } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Model aliases: named indirections (`alias:<name>`) to a concrete model, with
|
|
9
|
+
* ordered fallbacks. Global aliases are managed by super admins; project aliases by
|
|
10
|
+
* super admins, project admins and the project API key (not plain users, nor agent
|
|
11
|
+
* keys). Everyone in a project can read its aliases and the global ones.
|
|
12
|
+
*/
|
|
13
|
+
export class ModelAliasesApi extends HttpApi {
|
|
14
|
+
constructor(baseUrl: string, auth: string | AuthenticationProvider) {
|
|
15
|
+
super(baseUrl, auth);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Aliases visible to the caller (their project's and the global ones). Super admins
|
|
20
|
+
* can pass `projectId` to see another project's view.
|
|
21
|
+
*/
|
|
22
|
+
async list(
|
|
23
|
+
projectId?: string | null,
|
|
24
|
+
keyword?: string | null,
|
|
25
|
+
page?: number,
|
|
26
|
+
size?: number
|
|
27
|
+
): Promise<Paginated<ModelAlias>> {
|
|
28
|
+
const { page: p, size: s } = this.normalizePageParams(page, size);
|
|
29
|
+
const params: Record<string, unknown> = { page: p, size: s };
|
|
30
|
+
if (projectId) params.projectId = projectId;
|
|
31
|
+
if (keyword) params.keyword = keyword;
|
|
32
|
+
return this.httpGet<Paginated<ModelAlias>>('/model-aliases', params);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async get(id: string): Promise<ModelAlias> {
|
|
36
|
+
return this.httpGet<ModelAlias>('/model-aliases/' + id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Create an alias. Non-super-admins always create in their own project. */
|
|
40
|
+
async create(alias: ModelAliasInput): Promise<ModelAlias> {
|
|
41
|
+
return this.httpPost<ModelAlias>('/model-aliases', alias);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Change target, fallbacks, defaults and description. `name` and the scope are immutable. */
|
|
45
|
+
async update(id: string, alias: ModelAliasInput): Promise<ModelAlias> {
|
|
46
|
+
return this.httpPut<ModelAlias>('/model-aliases/' + id, alias);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Delete an alias. Refused with a 409 while agents still reference it: use
|
|
51
|
+
* {@link ModelAliasesApi.inUse} on the error to read which ones.
|
|
52
|
+
*/
|
|
53
|
+
async remove(id: string): Promise<void> {
|
|
54
|
+
await this.httpDelete('/model-aliases/' + id);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Agents that reference the alias, and in which model slot. */
|
|
58
|
+
async impact(id: string): Promise<AliasImpact> {
|
|
59
|
+
return this.httpGet<AliasImpact>('/model-aliases/' + id + '/impact');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Run the health check now (registry, announced retirements, credentials). Stores the
|
|
64
|
+
* result in `health` and updates the notifications; it never changes the alias.
|
|
65
|
+
*/
|
|
66
|
+
async check(id: string): Promise<ModelAlias> {
|
|
67
|
+
return this.httpPost<ModelAlias>('/model-aliases/' + id + '/check');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Replacement and fallback candidates for the alias' target, or for `model` (e.g. a
|
|
72
|
+
* fallback that went missing). A proposal only: nothing is applied.
|
|
73
|
+
*/
|
|
74
|
+
async suggestions(id: string, model?: string | null, limit?: number): Promise<AliasSuggestions> {
|
|
75
|
+
const params: Record<string, unknown> = {};
|
|
76
|
+
if (model) params.model = model;
|
|
77
|
+
if (limit !== undefined) params.limit = limit;
|
|
78
|
+
return this.httpGet<AliasSuggestions>('/model-aliases/' + id + '/suggestions', params);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The agents blocking a delete, when `error` is the 409 of {@link ModelAliasesApi.remove};
|
|
83
|
+
* `null` for any other error.
|
|
84
|
+
*/
|
|
85
|
+
static inUse(error: unknown): AliasImpact | null {
|
|
86
|
+
if (!(error instanceof ApiException) || error.statusCode !== 409) return null;
|
|
87
|
+
try {
|
|
88
|
+
const impact = JSON.parse(error.body)?.detail?.impact;
|
|
89
|
+
return impact && typeof impact.total === 'number' ? (impact as AliasImpact) : null;
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Prefix of a model name that references a model alias. */
|
|
2
|
+
export const ALIAS_PREFIX = 'alias:';
|
|
3
|
+
|
|
4
|
+
/** True when `modelName` is an `alias:<name>` reference. */
|
|
5
|
+
export function isAliasRef(modelName?: string | null): boolean {
|
|
6
|
+
return !!modelName && modelName.trim().toLowerCase().startsWith(ALIAS_PREFIX);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** `"alias:smart"` -> `"smart"`. Throws when `modelName` is not a reference. */
|
|
10
|
+
export function aliasNameFromRef(modelName: string): string {
|
|
11
|
+
if (!isAliasRef(modelName)) {
|
|
12
|
+
throw new Error(`Not a model alias reference: ${JSON.stringify(modelName)}`);
|
|
13
|
+
}
|
|
14
|
+
return modelName.trim().slice(ALIAS_PREFIX.length).trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `"smart"` -> `"alias:smart"`, to set as the `modelName` of an agent. */
|
|
18
|
+
export function aliasRef(name: string): string {
|
|
19
|
+
return ALIAS_PREFIX + name.trim();
|
|
20
|
+
}
|