@abpjs/ui 0.1.0 → 0.2.0-next.10

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/ai.d.ts ADDED
@@ -0,0 +1,584 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { SettingsPage, HostRequest } from '@abpjs/ui';
4
+
5
+ /** The site's AI page, with its header: what a host's catch-all route draws for `ai.admin`. */
6
+ declare function AiAdminPage(): react.JSX.Element;
7
+ /**
8
+ * The area's settings pages for a host to file under its sections: `ai.admin`, the site's AI (models, aliases, access,
9
+ * limits, usage, exports). The host gives where it opens and who sees it; the server checks every call anyway.
10
+ */
11
+ declare function aiPages(options: {
12
+ section: string;
13
+ href: string;
14
+ weight?: number;
15
+ title?: string;
16
+ about?: string;
17
+ visible?: SettingsPage['visible'];
18
+ }): SettingsPage[];
19
+
20
+ /**
21
+ * Whether the host keeps the connections itself (AbpAi's `IAiConnectionSource`), so the screens don't change them: the
22
+ * server's word (`connectionsKeptByHost`, AbpAi.HttpApi 0.8.0, on the site's settings or a scope's view).
23
+ */
24
+ declare function useHostKeepsConnections(told: boolean | null | undefined, scopeId?: string): boolean;
25
+ /**
26
+ * The site's AI in tabs: the models each connection offers, the site's aliases, what each scope may use and its
27
+ * limits, the site's limits, the usage ledger, a quick call to try an alias, and exports of calls.
28
+ */
29
+ declare function AiAdmin(): react.JSX.Element;
30
+
31
+ /**
32
+ * A scope's AI, for a host's own scope settings page (its header is the host's), from the scope's view (AbpAi.HttpApi
33
+ * 0.8.0, for whoever administers the scope): what the site and the scopes above open to it, its own connections'
34
+ * models while it may have them, its aliases over the ones from above, its limits inside theirs, its usage, and a
35
+ * quick call through an alias. `header` is the host's page header, drawn first in the screen's own column (and with
36
+ * the error when there's one), so the page reads as one column.
37
+ */
38
+ declare function AiScopeScreen({ scopeId, header }: {
39
+ scopeId: string;
40
+ header?: ReactNode;
41
+ }): react.JSX.Element;
42
+
43
+ interface components {
44
+ schemas: {
45
+ AiAliasInfo: {
46
+ /** Format: uuid */
47
+ id: string;
48
+ /** Format: uuid */
49
+ scopeId: null | string;
50
+ name: string;
51
+ targets: components["schemas"]["AiAliasTarget"][];
52
+ /** Format: date-time */
53
+ updatedAt: string;
54
+ };
55
+ AiAliasTarget: {
56
+ /** Format: uuid */
57
+ connectionId: string;
58
+ model?: null | string;
59
+ };
60
+ AiCallRow: {
61
+ /** Format: uuid */
62
+ id: string;
63
+ /** Format: date-time */
64
+ at: string;
65
+ state: string;
66
+ code: null | string;
67
+ error: null | string;
68
+ /** Format: uuid */
69
+ scopeId: null | string;
70
+ scope: null | string;
71
+ /** Format: uuid */
72
+ accountId: null | string;
73
+ /** Format: uuid */
74
+ onBehalfOf: null | string;
75
+ purpose: string;
76
+ aboutKind: null | string;
77
+ aboutId: null | string;
78
+ alias: string;
79
+ connection: string;
80
+ provider: string;
81
+ model: string;
82
+ dataClass: string;
83
+ streamed: boolean;
84
+ /** Format: int32 */
85
+ inputTokens: number | string;
86
+ /** Format: int32 */
87
+ outputTokens: number | string;
88
+ /** Format: int32 */
89
+ cacheWriteTokens: number | string;
90
+ /** Format: int32 */
91
+ cacheReadTokens: number | string;
92
+ /** Format: double */
93
+ cost: number | string;
94
+ /** Format: int32 */
95
+ durationMs: null | number | string;
96
+ accountName?: null | string;
97
+ onBehalfOfName?: null | string;
98
+ };
99
+ AiConnectionInfo: {
100
+ /** Format: uuid */
101
+ id: string;
102
+ /** Format: uuid */
103
+ scopeId: null | string;
104
+ name: string;
105
+ provider: string;
106
+ endpoint: string;
107
+ hasKey: boolean;
108
+ models: string[];
109
+ dataClasses: string[];
110
+ labels: string[];
111
+ settings: {
112
+ [key: string]: string;
113
+ };
114
+ /** Format: double */
115
+ inputPrice: number | string;
116
+ /** Format: double */
117
+ outputPrice: number | string;
118
+ modelPrices: {
119
+ [key: string]: components["schemas"]["AiPrice"];
120
+ };
121
+ structuredOutput: boolean;
122
+ enabled: boolean;
123
+ modelSettings?: {
124
+ [key: string]: components["schemas"]["AiModelSettings"];
125
+ };
126
+ /** Format: double */
127
+ cacheWritePrice?: null | number | string;
128
+ /** Format: double */
129
+ cacheReadPrice?: null | number | string;
130
+ /** Format: int32 */
131
+ idleTimeoutSeconds?: null | number | string;
132
+ /** Format: int32 */
133
+ totalTimeoutSeconds?: null | number | string;
134
+ type?: null | string;
135
+ test?: null | components["schemas"]["AiConnectionTest"];
136
+ };
137
+ AiConnectionInput: {
138
+ name: string;
139
+ provider: string;
140
+ models: string[];
141
+ dataClasses: string[];
142
+ modelSettings?: null | {
143
+ [key: string]: components["schemas"]["AiModelSettings"];
144
+ };
145
+ endpoint?: null | string;
146
+ apiKey?: null | string;
147
+ labels?: null | string[];
148
+ settings?: null | {
149
+ [key: string]: string;
150
+ };
151
+ /** Format: double */
152
+ inputPrice?: number | string;
153
+ /** Format: double */
154
+ outputPrice?: number | string;
155
+ modelPrices?: null | {
156
+ [key: string]: components["schemas"]["AiPrice"];
157
+ };
158
+ structuredOutput?: boolean;
159
+ enabled?: boolean;
160
+ /** Format: double */
161
+ cacheWritePrice?: null | number | string;
162
+ /** Format: double */
163
+ cacheReadPrice?: null | number | string;
164
+ /** Format: int32 */
165
+ idleTimeoutSeconds?: null | number | string;
166
+ /** Format: int32 */
167
+ totalTimeoutSeconds?: null | number | string;
168
+ test?: boolean;
169
+ };
170
+ AiConnectionTest: {
171
+ ok: boolean;
172
+ model: string;
173
+ /** Format: int32 */
174
+ elapsedMs: number | string;
175
+ /** Format: date-time */
176
+ at: string;
177
+ /** Format: int32 */
178
+ status?: null | number | string;
179
+ reason?: null | string;
180
+ };
181
+ AiExportInfo: {
182
+ /** Format: uuid */
183
+ id: string;
184
+ /** Format: date-time */
185
+ at: string;
186
+ /** Format: uuid */
187
+ actorId: string;
188
+ /** Format: date-time */
189
+ from: string;
190
+ /** Format: date-time */
191
+ to: string;
192
+ /** Format: uuid */
193
+ scopeId: null | string;
194
+ /** Format: int32 */
195
+ calls: number | string;
196
+ /** Format: int32 */
197
+ prompts: number | string;
198
+ truncated: boolean;
199
+ /** Format: int64 */
200
+ bytes: number | string;
201
+ /** Format: date-time */
202
+ expiresAt: string;
203
+ };
204
+ AiExportRequest: {
205
+ /** Format: date-time */
206
+ from: string;
207
+ /** Format: date-time */
208
+ to: string;
209
+ /** Format: uuid */
210
+ scopeId?: null | string;
211
+ };
212
+ AiLimitInfo: {
213
+ /** Format: uuid */
214
+ id: string;
215
+ /** Format: uuid */
216
+ scopeId: null | string;
217
+ kind: string;
218
+ period: string;
219
+ /** Format: double */
220
+ amount: number | string;
221
+ /** Format: uuid */
222
+ accountId: null | string;
223
+ /** Format: uuid */
224
+ groupId: null | string;
225
+ measure?: string;
226
+ };
227
+ AiLimitInput: {
228
+ kind: string;
229
+ period: string;
230
+ /** Format: double */
231
+ amount: number | string;
232
+ /** Format: uuid */
233
+ accountId?: null | string;
234
+ /** Format: uuid */
235
+ groupId?: null | string;
236
+ measure?: string;
237
+ };
238
+ AiLimitRef: {
239
+ /** Format: uuid */
240
+ limitId: string;
241
+ kind: string;
242
+ /** Format: uuid */
243
+ scopeId: null | string;
244
+ /** Format: uuid */
245
+ accountId: null | string;
246
+ period: string;
247
+ /** Format: double */
248
+ amount: number | string;
249
+ /** Format: double */
250
+ spent: number | string;
251
+ /** Format: date-time */
252
+ freesAt: string;
253
+ measure?: string;
254
+ };
255
+ AiModelRef: {
256
+ /** Format: uuid */
257
+ connectionId: string;
258
+ model: string;
259
+ };
260
+ AiModelSettings: {
261
+ name?: null | string;
262
+ enabled?: boolean;
263
+ tools?: boolean;
264
+ images?: boolean;
265
+ structuredOutput?: null | boolean;
266
+ embeds?: boolean;
267
+ /** Format: int32 */
268
+ contextTokens?: null | number | string;
269
+ /** Format: date-time */
270
+ priceSetAt?: null | string;
271
+ };
272
+ AiPrice: {
273
+ /** Format: double */
274
+ input: number | string;
275
+ /** Format: double */
276
+ output: number | string;
277
+ /** Format: double */
278
+ cacheWrite?: null | number | string;
279
+ /** Format: double */
280
+ cacheRead?: null | number | string;
281
+ };
282
+ AiRecentQuery: {
283
+ /** Format: date-time */
284
+ from: string;
285
+ /** Format: date-time */
286
+ to: string;
287
+ /** Format: uuid */
288
+ scopeId?: null | string;
289
+ /**
290
+ * Format: int32
291
+ * @default 50
292
+ */
293
+ count: number | string;
294
+ states?: null | string[];
295
+ };
296
+ AiRefusalAnswer: {
297
+ code: string;
298
+ message: string;
299
+ limit?: null | components["schemas"]["AiLimitRef"];
300
+ };
301
+ AiScopeAccessInfo: {
302
+ /** Format: uuid */
303
+ scopeId: string;
304
+ /** Format: uuid */
305
+ setOnScopeId: null | string;
306
+ allSiteModels: boolean;
307
+ siteModels: components["schemas"]["AiModelRef"][];
308
+ mayConnect: boolean;
309
+ };
310
+ AiScopeAccessInput: {
311
+ allSiteModels: boolean;
312
+ siteModels: null | components["schemas"]["AiModelRef"][];
313
+ mayConnect: boolean;
314
+ };
315
+ AiScopeModel: {
316
+ /** Format: uuid */
317
+ connectionId: string;
318
+ connection: string;
319
+ /** Format: uuid */
320
+ setOnScopeId: null | string;
321
+ model: string;
322
+ settings: components["schemas"]["AiModelSettings"];
323
+ price: components["schemas"]["AiPrice"];
324
+ own: boolean;
325
+ };
326
+ AiScopeView: {
327
+ /** Format: uuid */
328
+ scopeId: string;
329
+ models: components["schemas"]["AiScopeModel"][];
330
+ aliasesFromAbove: components["schemas"]["AiAliasInfo"][];
331
+ limitsFromAbove: components["schemas"]["AiLimitInfo"][];
332
+ mayConnect: boolean;
333
+ connectionsKeptByHost: boolean;
334
+ };
335
+ AiSiteSettings: {
336
+ scopesMayConnect: boolean;
337
+ keepPrompts: boolean;
338
+ /** Format: int32 */
339
+ promptDays: number | string;
340
+ scopeDataClasses: string[];
341
+ dataClasses: string[];
342
+ scopeAccess?: null | string;
343
+ connectionsKeptByHost?: boolean;
344
+ };
345
+ AiTryInput: {
346
+ alias: string;
347
+ prompt: string;
348
+ /** Format: uuid */
349
+ scopeId?: null | string;
350
+ dataClass?: null | string;
351
+ };
352
+ AiTryReply: {
353
+ text: string;
354
+ model: string;
355
+ connection: string;
356
+ usage: components["schemas"]["AiUsage"];
357
+ };
358
+ AiUsage: {
359
+ /** Format: int32 */
360
+ inputTokens: number | string;
361
+ /** Format: int32 */
362
+ outputTokens: number | string;
363
+ /** Format: double */
364
+ cost: number | string;
365
+ /** Format: int32 */
366
+ cacheWriteTokens?: number | string;
367
+ /** Format: int32 */
368
+ cacheReadTokens?: number | string;
369
+ };
370
+ AiUsageQuery: {
371
+ /** Format: date-time */
372
+ from: string;
373
+ /** Format: date-time */
374
+ to: string;
375
+ /** Format: uuid */
376
+ scopeId?: null | string;
377
+ /** @default scope */
378
+ groupBy: string;
379
+ /** Format: uuid */
380
+ accountId?: null | string;
381
+ purpose?: null | string;
382
+ model?: null | string;
383
+ states?: null | string[];
384
+ };
385
+ AiUsageReport: {
386
+ query: components["schemas"]["AiUsageQuery"];
387
+ rows: components["schemas"]["AiUsageRow"][];
388
+ total: components["schemas"]["AiUsageRow"];
389
+ };
390
+ AiUsageRow: {
391
+ key: string;
392
+ title: null | string;
393
+ /** Format: int32 */
394
+ calls: number | string;
395
+ /** Format: int64 */
396
+ inputTokens: number | string;
397
+ /** Format: int64 */
398
+ outputTokens: number | string;
399
+ /** Format: double */
400
+ cost: number | string;
401
+ /** Format: int32 */
402
+ failed?: number | string;
403
+ /** Format: int32 */
404
+ refused?: number | string;
405
+ /** Format: int64 */
406
+ cacheWriteTokens?: number | string;
407
+ /** Format: int64 */
408
+ cacheReadTokens?: number | string;
409
+ };
410
+ };
411
+ responses: never;
412
+ parameters: never;
413
+ requestBodies: never;
414
+ headers: never;
415
+ pathItems: never;
416
+ }
417
+
418
+ type Schemas = components['schemas'];
419
+ /** AbpAi.HttpApi's types, as its OpenAPI document gives them (`api.d.ts`). */
420
+ type AiTypes = Schemas;
421
+ type AiSite = Schemas['AiSiteSettings'];
422
+ type AiConnection = Schemas['AiConnectionInfo'];
423
+ type AiConnectionInput = Schemas['AiConnectionInput'];
424
+ type AiModelSettings = Schemas['AiModelSettings'];
425
+ type AiAlias = Schemas['AiAliasInfo'];
426
+ type AiAliasTarget = Schemas['AiAliasTarget'];
427
+ type AiLimit = Schemas['AiLimitInfo'];
428
+ type AiLimitInput = Schemas['AiLimitInput'];
429
+ type AiScopeAccess = Schemas['AiScopeAccessInfo'];
430
+ type AiScopeAccessInput = Schemas['AiScopeAccessInput'];
431
+ type AiUsageReport = Schemas['AiUsageReport'];
432
+ type AiUsageRow = Schemas['AiUsageRow'];
433
+ type AiCall = Schemas['AiCallRow'];
434
+ type AiExport = Schemas['AiExportInfo'];
435
+ type AiScopeView = Schemas['AiScopeView'];
436
+ type AiScopeModel = Schemas['AiScopeModel'];
437
+ type AiTryInput = Schemas['AiTryInput'];
438
+ type AiTryReply = Schemas['AiTryReply'];
439
+ /** A number the API may give as a string (its decimals and 64-bit counts). */
440
+ declare const num: (value: number | string | null | undefined) => number;
441
+
442
+ /** One model of one connection, as the screens show it: its settings with AbpAi's defaults filled in. */
443
+ interface AiModelRow {
444
+ /** `connectionId:model`: what an alias target and a scope's opened models are keyed by. */
445
+ key: string;
446
+ connectionId: string;
447
+ connection: string;
448
+ scopeId: string | null;
449
+ modelId: string;
450
+ name: string;
451
+ enabled: boolean;
452
+ tools: boolean;
453
+ images: boolean;
454
+ structuredOutput: boolean;
455
+ contextTokens: number | null;
456
+ /** Per million tokens; null when the model costs nothing in and nothing out. */
457
+ inputPrice: number | null;
458
+ outputPrice: number | null;
459
+ priceSetAt: string | null;
460
+ /** From a scope's view: the scope's own connection's model (true), or one the site or a scope above opens to it. */
461
+ own?: boolean;
462
+ }
463
+ declare const modelKey: (connectionId: string, model: string | null | undefined) => string;
464
+ /** Every model of the connections, in their order. A model with no settings is on and takes tools (AbpAi's defaults). */
465
+ declare function modelRows(connections: readonly AiConnection[]): AiModelRow[];
466
+ /** The models a scope may use, as its view gives them (AbpAi.HttpApi 0.8.0): the ones opened to it, then its own. */
467
+ declare function scopeModelRows(view: AiScopeView): AiModelRow[];
468
+ /**
469
+ * The connection as an update with one model's settings and price changed. Everything else goes back as it is; its key
470
+ * isn't sent, so the server keeps it.
471
+ */
472
+ declare function withModel(c: AiConnection, model: string, settings: AiModelSettings, price: {
473
+ input: number;
474
+ output: number;
475
+ } | null): AiConnectionInput;
476
+
477
+ /**
478
+ * What each scope may use: none by default; every model of the site's that's on, or some; its own connections; its
479
+ * limits. Every scope the host lists, with the ones AbpAi has settings for that it didn't list named through
480
+ * `scopes.name`. A host adds a column through the `ai.access.cell` slot and fields to the dialog through
481
+ * `ai.access.editor`.
482
+ */
483
+ declare function AccessPanel({ models }: {
484
+ models: AiModelRow[];
485
+ }): react.JSX.Element;
486
+
487
+ /**
488
+ * Aliases ("fast", "smart"): what skills and steps name. The site's or a scope's own are edited here, each to its first
489
+ * model (the ones after it, if any, stay as they are); a scope also sees the aliases it gets from above that it doesn't
490
+ * replace (`inherited`).
491
+ */
492
+ declare function AliasesPanel({ scopeId, aliases, inherited, models, onSaved }: {
493
+ scopeId?: string;
494
+ aliases: AiAlias[] | undefined;
495
+ inherited?: AiAlias[];
496
+ models: AiModelRow[];
497
+ onSaved: () => Promise<void> | void;
498
+ }): react.JSX.Element;
499
+
500
+ /**
501
+ * Exports of AI calls for support: a period's calls, up to 31 days, one line of JSON each (gzipped), with their prompts
502
+ * and replies only where the site keeps them. Asked for with the password again (the host's step-up); each export and
503
+ * download is in the security log. Kept a week.
504
+ */
505
+ declare function ExportsPanel({ scopeId }: {
506
+ scopeId?: string;
507
+ }): react.JSX.Element;
508
+
509
+ /** What a row of the editor says: what it counts (`cost`, `tokens`, `requests`) or `call-tokens`, over which period, how much. */
510
+ type LimitRow = {
511
+ kind: string;
512
+ period: string;
513
+ amount: string;
514
+ };
515
+ declare const LIMIT_KINDS: readonly ["cost", "tokens", "requests", "call-tokens"];
516
+ declare const LIMIT_PERIODS: readonly ["minute", "day", "month"];
517
+ /** The limits this editor shows and changes: a scope's (or the site's) totals and its tokens per reply, not a person's or a group's. */
518
+ declare const editableLimit: (l: AiLimit) => boolean;
519
+ declare const limitRow: (l: AiLimit) => LimitRow;
520
+ /**
521
+ * Saves the editor's rows on the site or a scope: the limits no row keeps as they were are deleted, then the new and
522
+ * changed ones are set. A person's and a group's limits are left alone.
523
+ */
524
+ declare function saveLimits(request: HostRequest, scopeId: string | null | undefined, before: readonly AiLimit[], rows: readonly LimitRow[]): Promise<void>;
525
+ /** "Cost per day: 5", "Tokens per reply: 2,000", and a person's default: "Cost per day for each person: 1". */
526
+ declare function useLimitText(): (l: AiLimit) => string;
527
+ /**
528
+ * Limits on a scope or the site: cost, tokens or requests per minute, day or month, and tokens per reply. With `onSave`
529
+ * it has its own Save button; with `onChange` (inside a larger form) it reports every change instead.
530
+ */
531
+ declare function LimitsEditor({ limits, onSave, onChange, busy, error }: {
532
+ limits: AiLimit[];
533
+ onSave?: (rows: LimitRow[]) => Promise<void> | void;
534
+ onChange?: (rows: LimitRow[]) => void;
535
+ busy?: boolean;
536
+ error?: string | null;
537
+ }): react.JSX.Element;
538
+
539
+ /**
540
+ * Models: each connection's, found by asking it, off until enabled, with what they can do and their prices per million
541
+ * tokens. Where the host keeps the connections itself (`hostKeeps`), the screen doesn't change them: each row shows the
542
+ * host's `ai.models.edit` and the panel its `ai.models.actions`; and what each model can do is the host's to say when
543
+ * it fills `ai.models.can` (its own record of it, where the gateway is told every model takes everything).
544
+ */
545
+ declare function ModelsPanel({ scopeId, connections, rows, loading, hostKeeps, onChanged, title, description }: {
546
+ scopeId?: string;
547
+ /** The connections whose models are listed and may be changed here. */
548
+ connections: AiConnection[] | undefined;
549
+ /** Rows to list in place of the connections' (a scope's opened models and its own); its own are still changed through `connections`. */
550
+ rows?: AiModelRow[];
551
+ loading?: boolean;
552
+ hostKeeps: boolean;
553
+ onChanged: () => Promise<void> | void;
554
+ title: string;
555
+ description: string;
556
+ }): react.JSX.Element;
557
+
558
+ /** How usage is summed, in the screens' words, and AbpAi's group for each. */
559
+ declare const USAGE_BY: {
560
+ readonly project: "scope";
561
+ readonly model: "model";
562
+ readonly purpose: "purpose";
563
+ readonly account: "account";
564
+ };
565
+ type UsageBy = keyof typeof USAGE_BY;
566
+ /** The usage ledger for the site or a scope: summed by what's asked for, this month or an earlier one, with the latest calls. */
567
+ declare function UsagePanel({ scopeId, by: byOptions }: {
568
+ scopeId?: string;
569
+ by: UsageBy[];
570
+ }): react.JSX.Element;
571
+
572
+ /**
573
+ * A quick call through an alias, as the person: through the same access, limits and data rules as any call, and on
574
+ * the ledger (AbpAi.HttpApi 0.8.0's `try`, for those who administer the site or the scope).
575
+ */
576
+ declare function TryPanel({ scopeId, aliases }: {
577
+ scopeId?: string;
578
+ aliases: string[];
579
+ }): react.JSX.Element;
580
+
581
+ /** The area's words, in English and Arabic; a host overrides any key through `AbpHost.texts.ai`. */
582
+ declare const useAiTexts: () => (key: string, values?: Record<string, string | number>) => string;
583
+
584
+ export { AccessPanel, AiAdmin, AiAdminPage, type AiAlias, type AiAliasTarget, type AiCall, type AiConnection, type AiConnectionInput, type AiExport, type AiLimit, type AiLimitInput, type AiModelRow, type AiModelSettings, type AiScopeAccess, type AiScopeAccessInput, type AiScopeModel, AiScopeScreen, type AiScopeView, type AiSite, type AiTryInput, type AiTryReply, type AiTypes, type AiUsageReport, type AiUsageRow, AliasesPanel, ExportsPanel, LIMIT_KINDS, LIMIT_PERIODS, type LimitRow, LimitsEditor, ModelsPanel, TryPanel, USAGE_BY, type UsageBy, UsagePanel, aiPages, editableLimit, limitRow, modelKey, modelRows, num, saveLimits, scopeModelRows, useAiTexts, useHostKeepsConnections, useLimitText, withModel };