@celljs/ta-protocol 4.15.1 → 4.15.2
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/esm/common/gateway-protocol.d.ts +244 -1
- package/esm/common/index.d.ts +1 -0
- package/esm/common/index.js +1 -0
- package/esm/common/ta-protocol.d.ts +2 -0
- package/esm/common/ta-protocol.js +2 -0
- package/esm/common/usage-protocol.d.ts +42 -0
- package/esm/common/usage-protocol.js +3 -0
- package/lib/common/gateway-protocol.d.ts +244 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/ta-protocol.d.ts +2 -0
- package/lib/common/ta-protocol.js +2 -0
- package/lib/common/usage-protocol.d.ts +43 -0
- package/lib/common/usage-protocol.js +6 -0
- package/package.json +1 -1
|
@@ -1,5 +1,107 @@
|
|
|
1
1
|
export declare const TaGatewayServer: unique symbol;
|
|
2
2
|
export declare const TA_GATEWAY_SERVICE = "TaGatewayServer";
|
|
3
|
+
import type { TaAgentActivity } from './usage-protocol.js';
|
|
4
|
+
/**
|
|
5
|
+
* Who one is on a gateway. `owner`: of TA_GATEWAY_ADMINS, set where the gateway runs, which nobody takes away
|
|
6
|
+
* from the console; manages everything and everyone. `admin`: made one by an owner in the console; manages
|
|
7
|
+
* members and their limits, not owners, other admins or the gateway's defaults. `member`: their own Ta only.
|
|
8
|
+
*/
|
|
9
|
+
export type TaGatewayRole = 'owner' | 'admin' | 'member';
|
|
10
|
+
/**
|
|
11
|
+
* What a member may use. In the defaults of the gateway, a limit left out is none; in the limits of one account,
|
|
12
|
+
* one left out is the default's and `null` is none.
|
|
13
|
+
*/
|
|
14
|
+
export interface TaGatewayLimits {
|
|
15
|
+
/** Minutes a month their sandbox may run, free. */
|
|
16
|
+
freeMinutes?: number | null;
|
|
17
|
+
/** Messages a minute they may send their agents (prompts, steering, follow-ups). */
|
|
18
|
+
promptsPerMinute?: number | null;
|
|
19
|
+
/** Pages connected at once. */
|
|
20
|
+
connections?: number | null;
|
|
21
|
+
/** The providers of sandboxes they may pick; all when left out. */
|
|
22
|
+
providers?: string[] | null;
|
|
23
|
+
/** Whether they may run their Ta in a Ta service of their own. */
|
|
24
|
+
own?: boolean | null;
|
|
25
|
+
}
|
|
26
|
+
/** Why one's Ta does not start: suspended by an administrator, or this month's free minutes used up. */
|
|
27
|
+
export type TaQuotaBlock = 'suspended' | 'minutes';
|
|
28
|
+
/** What one used of what one may, this month (of UTC), as one sees it and administrators do. */
|
|
29
|
+
export interface TaQuotaState {
|
|
30
|
+
/** `YYYY-MM`. */
|
|
31
|
+
month: string;
|
|
32
|
+
/** When the month's minutes and tokens start again. */
|
|
33
|
+
resetsAt: number;
|
|
34
|
+
/** Minutes the sandbox ran, as the gateway counts them; `bonus`: given by an administrator this month, on top of `limit`. */
|
|
35
|
+
minutes: {
|
|
36
|
+
used: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
bonus: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Tokens this month as the agents' sessions say: shown, not enforced. The sandbox is the member's, its files too;
|
|
42
|
+
* a limit of tokens holds only once the gateway provides the models (docs/design/ta-cloud.md, step five).
|
|
43
|
+
*/
|
|
44
|
+
tokens: {
|
|
45
|
+
used: number;
|
|
46
|
+
cost: number;
|
|
47
|
+
};
|
|
48
|
+
promptsPerMinute?: number;
|
|
49
|
+
connections?: number;
|
|
50
|
+
blocked?: TaQuotaBlock;
|
|
51
|
+
}
|
|
52
|
+
/** One hour of what agents took: tokens and dollars. */
|
|
53
|
+
export interface TaUsagePoint {
|
|
54
|
+
at: number;
|
|
55
|
+
input: number;
|
|
56
|
+
output: number;
|
|
57
|
+
/** Every token, read from a cache or written to one too. */
|
|
58
|
+
tokens: number;
|
|
59
|
+
cost: number;
|
|
60
|
+
turns: number;
|
|
61
|
+
}
|
|
62
|
+
export interface TaUsageShare {
|
|
63
|
+
tokens: number;
|
|
64
|
+
cost: number;
|
|
65
|
+
turns: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What the agents of the gateway, or of one account, took since `since`, by hour; a page groups the hours into
|
|
69
|
+
* its own days. A sandbox that does not run answers with what it said last (`stale`).
|
|
70
|
+
*/
|
|
71
|
+
export interface TaUsageTrend {
|
|
72
|
+
since: number;
|
|
73
|
+
hours: TaUsagePoint[];
|
|
74
|
+
byModel: (TaUsageShare & {
|
|
75
|
+
model: string;
|
|
76
|
+
})[];
|
|
77
|
+
byTenant: (TaUsageShare & {
|
|
78
|
+
tenantId: string;
|
|
79
|
+
})[];
|
|
80
|
+
/** Tenants whose numbers are those read last, their sandbox not running now. */
|
|
81
|
+
stale: string[];
|
|
82
|
+
readAt: number;
|
|
83
|
+
}
|
|
84
|
+
/** What an administrator did, kept by the gateway (audit.jsonl), newest first. */
|
|
85
|
+
export interface TaGatewayAuditEntry {
|
|
86
|
+
at: number;
|
|
87
|
+
/** The account that did it, or `cli` for `ta gateway link`. */
|
|
88
|
+
actor: string;
|
|
89
|
+
/** The method, such as `setTenantLimits`. */
|
|
90
|
+
action: string;
|
|
91
|
+
/** The account it was done to. */
|
|
92
|
+
target?: string;
|
|
93
|
+
detail?: string;
|
|
94
|
+
}
|
|
95
|
+
/** The defaults of the gateway and who manages it. */
|
|
96
|
+
export interface TaGatewayPolicy {
|
|
97
|
+
defaults: TaGatewayLimits;
|
|
98
|
+
/** Owners (`fixed`, of TA_GATEWAY_ADMINS) and admins made in the console. */
|
|
99
|
+
admins: {
|
|
100
|
+
account: string;
|
|
101
|
+
role: 'owner' | 'admin';
|
|
102
|
+
}[];
|
|
103
|
+
idleMinutes: number;
|
|
104
|
+
}
|
|
3
105
|
/**
|
|
4
106
|
* Where the Ta of a tenant runs: a sandbox of the gateway's provider (a container, a machine), or a Ta service
|
|
5
107
|
* of the user's own. `starting` until it answers; `failed` with `error` when it did not start.
|
|
@@ -34,12 +136,89 @@ export interface TaEnvironmentInfo {
|
|
|
34
136
|
/** That of a Ta service of the user's; never its token. */
|
|
35
137
|
url?: string;
|
|
36
138
|
}
|
|
139
|
+
/** What the sandbox of a tenant takes now, as far as its provider tells (`docker` does): none for a stopped one. */
|
|
140
|
+
export interface TaSandboxUsage {
|
|
141
|
+
/** Percent of one CPU: 150 is one and a half. */
|
|
142
|
+
cpu?: number;
|
|
143
|
+
/** Bytes of memory in use, and the most it may take. */
|
|
144
|
+
memory?: number;
|
|
145
|
+
memoryLimit?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* What an agent of a tenant does, as the console shows it: `working` in a turn, `waiting` on a dialog for the
|
|
149
|
+
* user, `asking` the user to decide, else `idle`.
|
|
150
|
+
*/
|
|
151
|
+
export type TaAgentStatus = 'working' | 'waiting' | 'asking' | 'idle';
|
|
152
|
+
/** How many conversations a tenant's Ta has open, and how many work or wait for their user now. */
|
|
153
|
+
export interface TaAgentCounts {
|
|
154
|
+
sessions: number;
|
|
155
|
+
working: number;
|
|
156
|
+
waiting: number;
|
|
157
|
+
}
|
|
158
|
+
/** What one conversation of a tenant's Ta has taken so far: pi's statistics of a session. */
|
|
159
|
+
export interface TaAgentStats {
|
|
160
|
+
userMessages: number;
|
|
161
|
+
assistantMessages: number;
|
|
162
|
+
toolCalls: number;
|
|
163
|
+
tokens: {
|
|
164
|
+
input: number;
|
|
165
|
+
output: number;
|
|
166
|
+
cacheRead: number;
|
|
167
|
+
cacheWrite: number;
|
|
168
|
+
total: number;
|
|
169
|
+
};
|
|
170
|
+
/** In dollars, as the model's prices make it; 0 for a model without them. */
|
|
171
|
+
cost: number;
|
|
172
|
+
/** Of its context window, 0 to 100, when known. */
|
|
173
|
+
context?: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A conversation open in a tenant's Ta, as an administrator sees it: what runs, on which model, at what cost;
|
|
177
|
+
* never what was said (its first or last message), only a name its user gave it.
|
|
178
|
+
*/
|
|
179
|
+
export interface TaAgentSession {
|
|
180
|
+
sessionId: string;
|
|
181
|
+
/** The name its user gave it, if any. */
|
|
182
|
+
name?: string;
|
|
183
|
+
cwd: string;
|
|
184
|
+
/** `<provider>/<model id>`. */
|
|
185
|
+
model?: string;
|
|
186
|
+
status: TaAgentStatus;
|
|
187
|
+
messageCount: number;
|
|
188
|
+
/** Pages attached to it now. */
|
|
189
|
+
attached: number;
|
|
190
|
+
createdAt: number;
|
|
191
|
+
updatedAt: number;
|
|
192
|
+
/** TaOpenSessionOptions.group: a task of the double, a member of a channel. */
|
|
193
|
+
group?: string;
|
|
194
|
+
stats?: TaAgentStats;
|
|
195
|
+
}
|
|
196
|
+
/** The agents of a tenant's Ta, read when asked (getTenantAgents). */
|
|
197
|
+
export interface TaTenantAgents {
|
|
198
|
+
sessions: TaAgentSession[];
|
|
199
|
+
totals: TaAgentCounts & {
|
|
200
|
+
toolCalls: number;
|
|
201
|
+
tokens: number;
|
|
202
|
+
cost: number;
|
|
203
|
+
};
|
|
204
|
+
readAt: number;
|
|
205
|
+
}
|
|
37
206
|
/** A tenant, as an administrator sees it: one per account, its own sandbox. */
|
|
38
207
|
export interface TaGatewayTenant {
|
|
39
208
|
id: string;
|
|
40
209
|
account: string;
|
|
41
210
|
name?: string;
|
|
211
|
+
avatar?: string;
|
|
42
212
|
environment: TaEnvironmentInfo;
|
|
213
|
+
/** Read with the console (getConsole), of a running sandbox whose provider tells it. */
|
|
214
|
+
usage?: TaSandboxUsage;
|
|
215
|
+
/** Read with the console, of a running sandbox of the gateway's; none for a Ta service of the user's. */
|
|
216
|
+
agents?: TaAgentCounts;
|
|
217
|
+
role: TaGatewayRole;
|
|
218
|
+
quota: TaQuotaState;
|
|
219
|
+
/** Its own limits, over the defaults. */
|
|
220
|
+
limits?: TaGatewayLimits;
|
|
221
|
+
suspended?: boolean;
|
|
43
222
|
/** Browsers connected now. */
|
|
44
223
|
connections: number;
|
|
45
224
|
createdAt: number;
|
|
@@ -57,8 +236,39 @@ export interface TaGatewayInfo {
|
|
|
57
236
|
options: TaEnvironmentOption[];
|
|
58
237
|
/** Whether a Ta service of one's own may be used (`ownEnvironments` of sandboxes.json). */
|
|
59
238
|
own: boolean;
|
|
60
|
-
/** May let accounts in
|
|
239
|
+
/** May let accounts in and see the tenants: an owner or an admin. */
|
|
61
240
|
admin: boolean;
|
|
241
|
+
role: TaGatewayRole;
|
|
242
|
+
/** What one used this month of what one may. */
|
|
243
|
+
quota: TaQuotaState;
|
|
244
|
+
}
|
|
245
|
+
/** A provider of sandboxes, as the console shows it. */
|
|
246
|
+
export interface TaGatewayProvider extends TaEnvironmentOption {
|
|
247
|
+
/** That of tenants that picked none. */
|
|
248
|
+
default: boolean;
|
|
249
|
+
/** The tenants whose Ta it runs. */
|
|
250
|
+
tenants: number;
|
|
251
|
+
/** Whether the console can show the log of a sandbox of it (getTenantLogs). */
|
|
252
|
+
logs: boolean;
|
|
253
|
+
}
|
|
254
|
+
/** The console of a gateway, for its administrators: the gateway, its providers, its tenants. */
|
|
255
|
+
export interface TaGatewayConsole {
|
|
256
|
+
/** Of Ta, which the gateway is part of. */
|
|
257
|
+
version?: string;
|
|
258
|
+
startedAt: number;
|
|
259
|
+
/** TA_PUBLIC_URL: where people reach the gateway. */
|
|
260
|
+
publicUrl?: string;
|
|
261
|
+
providers: TaGatewayProvider[];
|
|
262
|
+
/** Whether users may run their Ta in a Ta service of their own. */
|
|
263
|
+
own: boolean;
|
|
264
|
+
/** Minutes after which a sandbox nobody is connected to stops; 0: it keeps running. */
|
|
265
|
+
idleMinutes: number;
|
|
266
|
+
tenants: TaGatewayTenant[];
|
|
267
|
+
/** Accounts that signed in and wait to be let in (TaAccessServer). */
|
|
268
|
+
requests: number;
|
|
269
|
+
/** That of the one who looks. */
|
|
270
|
+
role: TaGatewayRole;
|
|
271
|
+
policy: TaGatewayPolicy;
|
|
62
272
|
}
|
|
63
273
|
/**
|
|
64
274
|
* `ta gateway`: each account that signs in is a tenant with a Ta of its own, in a sandbox of its own, which
|
|
@@ -78,4 +288,37 @@ export interface TaGatewayServer {
|
|
|
78
288
|
listTenants(): Promise<TaGatewayTenant[]>;
|
|
79
289
|
/** For administrators: stops the sandbox of a tenant, which starts again when it connects. */
|
|
80
290
|
stopTenant(tenantId: string): Promise<void>;
|
|
291
|
+
/** For administrators: the gateway, its providers and its tenants, with what their sandboxes take. */
|
|
292
|
+
getConsole(): Promise<TaGatewayConsole>;
|
|
293
|
+
/** For administrators: starts the sandbox of a tenant, whoever is connected; resolves once its Ta answers. */
|
|
294
|
+
startTenant(tenantId: string): Promise<void>;
|
|
295
|
+
/** For administrators: stops the sandbox of a tenant and starts it again; its browsers connect again. */
|
|
296
|
+
restartTenant(tenantId: string): Promise<void>;
|
|
297
|
+
/** For administrators: the conversations open in the Ta of a tenant, with what each takes; none when its sandbox does not run. */
|
|
298
|
+
getTenantAgents(tenantId: string): Promise<TaTenantAgents>;
|
|
299
|
+
/** For administrators: the last lines (200 by default, 2000 at most) its sandbox wrote, when its provider keeps them. */
|
|
300
|
+
getTenantLogs(tenantId: string, lines?: number): Promise<string>;
|
|
301
|
+
/**
|
|
302
|
+
* For administrators: a link that signs in as the account once, within a day, and lets it in, as
|
|
303
|
+
* `ta gateway link` prints: its path (`/sign-in/link/…`), to put after the address of the gateway.
|
|
304
|
+
*/
|
|
305
|
+
createSignInLink(account: string, name?: string): Promise<string>;
|
|
306
|
+
/** For administrators: what agents took, of the gateway or of one tenant, over the last `days` (1 to 31). */
|
|
307
|
+
getUsageTrend(days: number, tenantId?: string): Promise<TaUsageTrend>;
|
|
308
|
+
/** For administrators: the latest tool calls and failures of an agent of a tenant, newest first. */
|
|
309
|
+
getAgentActivity(tenantId: string, sessionId: string): Promise<TaAgentActivity[]>;
|
|
310
|
+
/** For administrators: the defaults and who manages the gateway. */
|
|
311
|
+
getPolicy(): Promise<TaGatewayPolicy>;
|
|
312
|
+
/** For owners: the limits of everyone without their own. */
|
|
313
|
+
setDefaultLimits(limits: TaGatewayLimits): Promise<TaGatewayPolicy>;
|
|
314
|
+
/** For administrators, of a member (owners: of anyone): their own limits over the defaults; `null` drops them. */
|
|
315
|
+
setTenantLimits(tenantId: string, limits: TaGatewayLimits | null): Promise<void>;
|
|
316
|
+
/** For administrators: free minutes this month on top of the limit (negative takes some back, never below none). */
|
|
317
|
+
grantMinutes(tenantId: string, minutes: number): Promise<void>;
|
|
318
|
+
/** For administrators: a suspended account's Ta stops and does not start until it is let go again. */
|
|
319
|
+
setSuspended(tenantId: string, suspended: boolean): Promise<void>;
|
|
320
|
+
/** For owners: makes an account that signed in an admin, or a member again. Owners stay owners. */
|
|
321
|
+
setRole(account: string, role: 'admin' | 'member'): Promise<TaGatewayPolicy>;
|
|
322
|
+
/** For administrators: what administrators did lately, newest first, `limit` at most (100 by default). */
|
|
323
|
+
getAudit(limit?: number): Promise<TaGatewayAuditEntry[]>;
|
|
81
324
|
}
|
package/esm/common/index.d.ts
CHANGED
package/esm/common/index.js
CHANGED
|
@@ -13,5 +13,6 @@ export * from './settings-protocol.js';
|
|
|
13
13
|
export * from './ta-extension-host.js';
|
|
14
14
|
export * from './ta-protocol.js';
|
|
15
15
|
export * from './team-protocol.js';
|
|
16
|
+
export * from './usage-protocol.js';
|
|
16
17
|
export * from './workspace-protocol.js';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -80,6 +80,8 @@ export declare const TaErrorCode: {
|
|
|
80
80
|
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
81
81
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
82
82
|
readonly ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED';
|
|
83
|
+
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
84
|
+
readonly RATE_LIMITED: 'CELL_TA_RATE_LIMITED';
|
|
83
85
|
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
84
86
|
readonly FORBIDDEN: 'CELL_TA_FORBIDDEN';
|
|
85
87
|
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
@@ -34,6 +34,8 @@ export const TaErrorCode = {
|
|
|
34
34
|
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
35
35
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
36
36
|
ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
|
|
37
|
+
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
38
|
+
RATE_LIMITED: 'CELL_TA_RATE_LIMITED',
|
|
37
39
|
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
38
40
|
FORBIDDEN: 'CELL_TA_FORBIDDEN',
|
|
39
41
|
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const TaUsageServer: unique symbol;
|
|
2
|
+
export declare const TA_USAGE_SERVICE = "TaUsageServer";
|
|
3
|
+
/** What the turns of a model took in one hour (`at`, its start), from the sessions of this Ta. */
|
|
4
|
+
export interface TaUsageBucket {
|
|
5
|
+
at: number;
|
|
6
|
+
/** `<provider>/<model id>`. */
|
|
7
|
+
model: string;
|
|
8
|
+
input: number;
|
|
9
|
+
output: number;
|
|
10
|
+
cacheRead: number;
|
|
11
|
+
cacheWrite: number;
|
|
12
|
+
/** In dollars, as the model's prices make it. */
|
|
13
|
+
cost: number;
|
|
14
|
+
/** Answers of the model. */
|
|
15
|
+
turns: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Something an agent did lately, as one watching it sees it: a tool it called (its name, whether it worked, how
|
|
19
|
+
* long it took) or a call of the model that failed. Never its arguments or what it returned; of an error, its first
|
|
20
|
+
* line, cut short.
|
|
21
|
+
*/
|
|
22
|
+
export interface TaAgentActivity {
|
|
23
|
+
at: number;
|
|
24
|
+
kind: 'tool' | 'model';
|
|
25
|
+
/** The tool's name, or the model's. */
|
|
26
|
+
name: string;
|
|
27
|
+
ok: boolean;
|
|
28
|
+
/** A tool call without its result yet. */
|
|
29
|
+
running?: boolean;
|
|
30
|
+
error?: string;
|
|
31
|
+
ms?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the agents of this Ta took and did, read from the files of its sessions: for a gateway's console, and
|
|
35
|
+
* any page that shows spending. Nothing said in them leaves.
|
|
36
|
+
*/
|
|
37
|
+
export interface TaUsageServer {
|
|
38
|
+
/** The hours since `since` (a time), by model; an hour with nothing is left out. */
|
|
39
|
+
getUsage(since: number): Promise<TaUsageBucket[]>;
|
|
40
|
+
/** The latest of what the agent of an open session did, newest first, `limit` at most (50 by default, 200 at most). */
|
|
41
|
+
getActivity(sessionId: string, limit?: number): Promise<TaAgentActivity[]>;
|
|
42
|
+
}
|
|
@@ -1,5 +1,107 @@
|
|
|
1
1
|
export declare const TaGatewayServer: unique symbol;
|
|
2
2
|
export declare const TA_GATEWAY_SERVICE = "TaGatewayServer";
|
|
3
|
+
import type { TaAgentActivity } from './usage-protocol';
|
|
4
|
+
/**
|
|
5
|
+
* Who one is on a gateway. `owner`: of TA_GATEWAY_ADMINS, set where the gateway runs, which nobody takes away
|
|
6
|
+
* from the console; manages everything and everyone. `admin`: made one by an owner in the console; manages
|
|
7
|
+
* members and their limits, not owners, other admins or the gateway's defaults. `member`: their own Ta only.
|
|
8
|
+
*/
|
|
9
|
+
export type TaGatewayRole = 'owner' | 'admin' | 'member';
|
|
10
|
+
/**
|
|
11
|
+
* What a member may use. In the defaults of the gateway, a limit left out is none; in the limits of one account,
|
|
12
|
+
* one left out is the default's and `null` is none.
|
|
13
|
+
*/
|
|
14
|
+
export interface TaGatewayLimits {
|
|
15
|
+
/** Minutes a month their sandbox may run, free. */
|
|
16
|
+
freeMinutes?: number | null;
|
|
17
|
+
/** Messages a minute they may send their agents (prompts, steering, follow-ups). */
|
|
18
|
+
promptsPerMinute?: number | null;
|
|
19
|
+
/** Pages connected at once. */
|
|
20
|
+
connections?: number | null;
|
|
21
|
+
/** The providers of sandboxes they may pick; all when left out. */
|
|
22
|
+
providers?: string[] | null;
|
|
23
|
+
/** Whether they may run their Ta in a Ta service of their own. */
|
|
24
|
+
own?: boolean | null;
|
|
25
|
+
}
|
|
26
|
+
/** Why one's Ta does not start: suspended by an administrator, or this month's free minutes used up. */
|
|
27
|
+
export type TaQuotaBlock = 'suspended' | 'minutes';
|
|
28
|
+
/** What one used of what one may, this month (of UTC), as one sees it and administrators do. */
|
|
29
|
+
export interface TaQuotaState {
|
|
30
|
+
/** `YYYY-MM`. */
|
|
31
|
+
month: string;
|
|
32
|
+
/** When the month's minutes and tokens start again. */
|
|
33
|
+
resetsAt: number;
|
|
34
|
+
/** Minutes the sandbox ran, as the gateway counts them; `bonus`: given by an administrator this month, on top of `limit`. */
|
|
35
|
+
minutes: {
|
|
36
|
+
used: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
bonus: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Tokens this month as the agents' sessions say: shown, not enforced. The sandbox is the member's, its files too;
|
|
42
|
+
* a limit of tokens holds only once the gateway provides the models (docs/design/ta-cloud.md, step five).
|
|
43
|
+
*/
|
|
44
|
+
tokens: {
|
|
45
|
+
used: number;
|
|
46
|
+
cost: number;
|
|
47
|
+
};
|
|
48
|
+
promptsPerMinute?: number;
|
|
49
|
+
connections?: number;
|
|
50
|
+
blocked?: TaQuotaBlock;
|
|
51
|
+
}
|
|
52
|
+
/** One hour of what agents took: tokens and dollars. */
|
|
53
|
+
export interface TaUsagePoint {
|
|
54
|
+
at: number;
|
|
55
|
+
input: number;
|
|
56
|
+
output: number;
|
|
57
|
+
/** Every token, read from a cache or written to one too. */
|
|
58
|
+
tokens: number;
|
|
59
|
+
cost: number;
|
|
60
|
+
turns: number;
|
|
61
|
+
}
|
|
62
|
+
export interface TaUsageShare {
|
|
63
|
+
tokens: number;
|
|
64
|
+
cost: number;
|
|
65
|
+
turns: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What the agents of the gateway, or of one account, took since `since`, by hour; a page groups the hours into
|
|
69
|
+
* its own days. A sandbox that does not run answers with what it said last (`stale`).
|
|
70
|
+
*/
|
|
71
|
+
export interface TaUsageTrend {
|
|
72
|
+
since: number;
|
|
73
|
+
hours: TaUsagePoint[];
|
|
74
|
+
byModel: (TaUsageShare & {
|
|
75
|
+
model: string;
|
|
76
|
+
})[];
|
|
77
|
+
byTenant: (TaUsageShare & {
|
|
78
|
+
tenantId: string;
|
|
79
|
+
})[];
|
|
80
|
+
/** Tenants whose numbers are those read last, their sandbox not running now. */
|
|
81
|
+
stale: string[];
|
|
82
|
+
readAt: number;
|
|
83
|
+
}
|
|
84
|
+
/** What an administrator did, kept by the gateway (audit.jsonl), newest first. */
|
|
85
|
+
export interface TaGatewayAuditEntry {
|
|
86
|
+
at: number;
|
|
87
|
+
/** The account that did it, or `cli` for `ta gateway link`. */
|
|
88
|
+
actor: string;
|
|
89
|
+
/** The method, such as `setTenantLimits`. */
|
|
90
|
+
action: string;
|
|
91
|
+
/** The account it was done to. */
|
|
92
|
+
target?: string;
|
|
93
|
+
detail?: string;
|
|
94
|
+
}
|
|
95
|
+
/** The defaults of the gateway and who manages it. */
|
|
96
|
+
export interface TaGatewayPolicy {
|
|
97
|
+
defaults: TaGatewayLimits;
|
|
98
|
+
/** Owners (`fixed`, of TA_GATEWAY_ADMINS) and admins made in the console. */
|
|
99
|
+
admins: {
|
|
100
|
+
account: string;
|
|
101
|
+
role: 'owner' | 'admin';
|
|
102
|
+
}[];
|
|
103
|
+
idleMinutes: number;
|
|
104
|
+
}
|
|
3
105
|
/**
|
|
4
106
|
* Where the Ta of a tenant runs: a sandbox of the gateway's provider (a container, a machine), or a Ta service
|
|
5
107
|
* of the user's own. `starting` until it answers; `failed` with `error` when it did not start.
|
|
@@ -34,12 +136,89 @@ export interface TaEnvironmentInfo {
|
|
|
34
136
|
/** That of a Ta service of the user's; never its token. */
|
|
35
137
|
url?: string;
|
|
36
138
|
}
|
|
139
|
+
/** What the sandbox of a tenant takes now, as far as its provider tells (`docker` does): none for a stopped one. */
|
|
140
|
+
export interface TaSandboxUsage {
|
|
141
|
+
/** Percent of one CPU: 150 is one and a half. */
|
|
142
|
+
cpu?: number;
|
|
143
|
+
/** Bytes of memory in use, and the most it may take. */
|
|
144
|
+
memory?: number;
|
|
145
|
+
memoryLimit?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* What an agent of a tenant does, as the console shows it: `working` in a turn, `waiting` on a dialog for the
|
|
149
|
+
* user, `asking` the user to decide, else `idle`.
|
|
150
|
+
*/
|
|
151
|
+
export type TaAgentStatus = 'working' | 'waiting' | 'asking' | 'idle';
|
|
152
|
+
/** How many conversations a tenant's Ta has open, and how many work or wait for their user now. */
|
|
153
|
+
export interface TaAgentCounts {
|
|
154
|
+
sessions: number;
|
|
155
|
+
working: number;
|
|
156
|
+
waiting: number;
|
|
157
|
+
}
|
|
158
|
+
/** What one conversation of a tenant's Ta has taken so far: pi's statistics of a session. */
|
|
159
|
+
export interface TaAgentStats {
|
|
160
|
+
userMessages: number;
|
|
161
|
+
assistantMessages: number;
|
|
162
|
+
toolCalls: number;
|
|
163
|
+
tokens: {
|
|
164
|
+
input: number;
|
|
165
|
+
output: number;
|
|
166
|
+
cacheRead: number;
|
|
167
|
+
cacheWrite: number;
|
|
168
|
+
total: number;
|
|
169
|
+
};
|
|
170
|
+
/** In dollars, as the model's prices make it; 0 for a model without them. */
|
|
171
|
+
cost: number;
|
|
172
|
+
/** Of its context window, 0 to 100, when known. */
|
|
173
|
+
context?: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A conversation open in a tenant's Ta, as an administrator sees it: what runs, on which model, at what cost;
|
|
177
|
+
* never what was said (its first or last message), only a name its user gave it.
|
|
178
|
+
*/
|
|
179
|
+
export interface TaAgentSession {
|
|
180
|
+
sessionId: string;
|
|
181
|
+
/** The name its user gave it, if any. */
|
|
182
|
+
name?: string;
|
|
183
|
+
cwd: string;
|
|
184
|
+
/** `<provider>/<model id>`. */
|
|
185
|
+
model?: string;
|
|
186
|
+
status: TaAgentStatus;
|
|
187
|
+
messageCount: number;
|
|
188
|
+
/** Pages attached to it now. */
|
|
189
|
+
attached: number;
|
|
190
|
+
createdAt: number;
|
|
191
|
+
updatedAt: number;
|
|
192
|
+
/** TaOpenSessionOptions.group: a task of the double, a member of a channel. */
|
|
193
|
+
group?: string;
|
|
194
|
+
stats?: TaAgentStats;
|
|
195
|
+
}
|
|
196
|
+
/** The agents of a tenant's Ta, read when asked (getTenantAgents). */
|
|
197
|
+
export interface TaTenantAgents {
|
|
198
|
+
sessions: TaAgentSession[];
|
|
199
|
+
totals: TaAgentCounts & {
|
|
200
|
+
toolCalls: number;
|
|
201
|
+
tokens: number;
|
|
202
|
+
cost: number;
|
|
203
|
+
};
|
|
204
|
+
readAt: number;
|
|
205
|
+
}
|
|
37
206
|
/** A tenant, as an administrator sees it: one per account, its own sandbox. */
|
|
38
207
|
export interface TaGatewayTenant {
|
|
39
208
|
id: string;
|
|
40
209
|
account: string;
|
|
41
210
|
name?: string;
|
|
211
|
+
avatar?: string;
|
|
42
212
|
environment: TaEnvironmentInfo;
|
|
213
|
+
/** Read with the console (getConsole), of a running sandbox whose provider tells it. */
|
|
214
|
+
usage?: TaSandboxUsage;
|
|
215
|
+
/** Read with the console, of a running sandbox of the gateway's; none for a Ta service of the user's. */
|
|
216
|
+
agents?: TaAgentCounts;
|
|
217
|
+
role: TaGatewayRole;
|
|
218
|
+
quota: TaQuotaState;
|
|
219
|
+
/** Its own limits, over the defaults. */
|
|
220
|
+
limits?: TaGatewayLimits;
|
|
221
|
+
suspended?: boolean;
|
|
43
222
|
/** Browsers connected now. */
|
|
44
223
|
connections: number;
|
|
45
224
|
createdAt: number;
|
|
@@ -57,8 +236,39 @@ export interface TaGatewayInfo {
|
|
|
57
236
|
options: TaEnvironmentOption[];
|
|
58
237
|
/** Whether a Ta service of one's own may be used (`ownEnvironments` of sandboxes.json). */
|
|
59
238
|
own: boolean;
|
|
60
|
-
/** May let accounts in
|
|
239
|
+
/** May let accounts in and see the tenants: an owner or an admin. */
|
|
61
240
|
admin: boolean;
|
|
241
|
+
role: TaGatewayRole;
|
|
242
|
+
/** What one used this month of what one may. */
|
|
243
|
+
quota: TaQuotaState;
|
|
244
|
+
}
|
|
245
|
+
/** A provider of sandboxes, as the console shows it. */
|
|
246
|
+
export interface TaGatewayProvider extends TaEnvironmentOption {
|
|
247
|
+
/** That of tenants that picked none. */
|
|
248
|
+
default: boolean;
|
|
249
|
+
/** The tenants whose Ta it runs. */
|
|
250
|
+
tenants: number;
|
|
251
|
+
/** Whether the console can show the log of a sandbox of it (getTenantLogs). */
|
|
252
|
+
logs: boolean;
|
|
253
|
+
}
|
|
254
|
+
/** The console of a gateway, for its administrators: the gateway, its providers, its tenants. */
|
|
255
|
+
export interface TaGatewayConsole {
|
|
256
|
+
/** Of Ta, which the gateway is part of. */
|
|
257
|
+
version?: string;
|
|
258
|
+
startedAt: number;
|
|
259
|
+
/** TA_PUBLIC_URL: where people reach the gateway. */
|
|
260
|
+
publicUrl?: string;
|
|
261
|
+
providers: TaGatewayProvider[];
|
|
262
|
+
/** Whether users may run their Ta in a Ta service of their own. */
|
|
263
|
+
own: boolean;
|
|
264
|
+
/** Minutes after which a sandbox nobody is connected to stops; 0: it keeps running. */
|
|
265
|
+
idleMinutes: number;
|
|
266
|
+
tenants: TaGatewayTenant[];
|
|
267
|
+
/** Accounts that signed in and wait to be let in (TaAccessServer). */
|
|
268
|
+
requests: number;
|
|
269
|
+
/** That of the one who looks. */
|
|
270
|
+
role: TaGatewayRole;
|
|
271
|
+
policy: TaGatewayPolicy;
|
|
62
272
|
}
|
|
63
273
|
/**
|
|
64
274
|
* `ta gateway`: each account that signs in is a tenant with a Ta of its own, in a sandbox of its own, which
|
|
@@ -78,5 +288,38 @@ export interface TaGatewayServer {
|
|
|
78
288
|
listTenants(): Promise<TaGatewayTenant[]>;
|
|
79
289
|
/** For administrators: stops the sandbox of a tenant, which starts again when it connects. */
|
|
80
290
|
stopTenant(tenantId: string): Promise<void>;
|
|
291
|
+
/** For administrators: the gateway, its providers and its tenants, with what their sandboxes take. */
|
|
292
|
+
getConsole(): Promise<TaGatewayConsole>;
|
|
293
|
+
/** For administrators: starts the sandbox of a tenant, whoever is connected; resolves once its Ta answers. */
|
|
294
|
+
startTenant(tenantId: string): Promise<void>;
|
|
295
|
+
/** For administrators: stops the sandbox of a tenant and starts it again; its browsers connect again. */
|
|
296
|
+
restartTenant(tenantId: string): Promise<void>;
|
|
297
|
+
/** For administrators: the conversations open in the Ta of a tenant, with what each takes; none when its sandbox does not run. */
|
|
298
|
+
getTenantAgents(tenantId: string): Promise<TaTenantAgents>;
|
|
299
|
+
/** For administrators: the last lines (200 by default, 2000 at most) its sandbox wrote, when its provider keeps them. */
|
|
300
|
+
getTenantLogs(tenantId: string, lines?: number): Promise<string>;
|
|
301
|
+
/**
|
|
302
|
+
* For administrators: a link that signs in as the account once, within a day, and lets it in, as
|
|
303
|
+
* `ta gateway link` prints: its path (`/sign-in/link/…`), to put after the address of the gateway.
|
|
304
|
+
*/
|
|
305
|
+
createSignInLink(account: string, name?: string): Promise<string>;
|
|
306
|
+
/** For administrators: what agents took, of the gateway or of one tenant, over the last `days` (1 to 31). */
|
|
307
|
+
getUsageTrend(days: number, tenantId?: string): Promise<TaUsageTrend>;
|
|
308
|
+
/** For administrators: the latest tool calls and failures of an agent of a tenant, newest first. */
|
|
309
|
+
getAgentActivity(tenantId: string, sessionId: string): Promise<TaAgentActivity[]>;
|
|
310
|
+
/** For administrators: the defaults and who manages the gateway. */
|
|
311
|
+
getPolicy(): Promise<TaGatewayPolicy>;
|
|
312
|
+
/** For owners: the limits of everyone without their own. */
|
|
313
|
+
setDefaultLimits(limits: TaGatewayLimits): Promise<TaGatewayPolicy>;
|
|
314
|
+
/** For administrators, of a member (owners: of anyone): their own limits over the defaults; `null` drops them. */
|
|
315
|
+
setTenantLimits(tenantId: string, limits: TaGatewayLimits | null): Promise<void>;
|
|
316
|
+
/** For administrators: free minutes this month on top of the limit (negative takes some back, never below none). */
|
|
317
|
+
grantMinutes(tenantId: string, minutes: number): Promise<void>;
|
|
318
|
+
/** For administrators: a suspended account's Ta stops and does not start until it is let go again. */
|
|
319
|
+
setSuspended(tenantId: string, suspended: boolean): Promise<void>;
|
|
320
|
+
/** For owners: makes an account that signed in an admin, or a member again. Owners stay owners. */
|
|
321
|
+
setRole(account: string, role: 'admin' | 'member'): Promise<TaGatewayPolicy>;
|
|
322
|
+
/** For administrators: what administrators did lately, newest first, `limit` at most (100 by default). */
|
|
323
|
+
getAudit(limit?: number): Promise<TaGatewayAuditEntry[]>;
|
|
81
324
|
}
|
|
82
325
|
//# sourceMappingURL=gateway-protocol.d.ts.map
|
package/lib/common/index.d.ts
CHANGED
package/lib/common/index.js
CHANGED
|
@@ -29,5 +29,6 @@ __exportStar(require("./settings-protocol"), exports);
|
|
|
29
29
|
__exportStar(require("./ta-extension-host"), exports);
|
|
30
30
|
__exportStar(require("./ta-protocol"), exports);
|
|
31
31
|
__exportStar(require("./team-protocol"), exports);
|
|
32
|
+
__exportStar(require("./usage-protocol"), exports);
|
|
32
33
|
__exportStar(require("./workspace-protocol"), exports);
|
|
33
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -80,6 +80,8 @@ export declare const TaErrorCode: {
|
|
|
80
80
|
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
81
81
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
82
82
|
readonly ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED';
|
|
83
|
+
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
84
|
+
readonly RATE_LIMITED: 'CELL_TA_RATE_LIMITED';
|
|
83
85
|
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
84
86
|
readonly FORBIDDEN: 'CELL_TA_FORBIDDEN';
|
|
85
87
|
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
@@ -37,6 +37,8 @@ exports.TaErrorCode = {
|
|
|
37
37
|
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
38
38
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
39
39
|
ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
|
|
40
|
+
/** Behind a gateway: more messages a minute than one may send; try again in a moment. */
|
|
41
|
+
RATE_LIMITED: 'CELL_TA_RATE_LIMITED',
|
|
40
42
|
/** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
|
|
41
43
|
FORBIDDEN: 'CELL_TA_FORBIDDEN',
|
|
42
44
|
/** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const TaUsageServer: unique symbol;
|
|
2
|
+
export declare const TA_USAGE_SERVICE = "TaUsageServer";
|
|
3
|
+
/** What the turns of a model took in one hour (`at`, its start), from the sessions of this Ta. */
|
|
4
|
+
export interface TaUsageBucket {
|
|
5
|
+
at: number;
|
|
6
|
+
/** `<provider>/<model id>`. */
|
|
7
|
+
model: string;
|
|
8
|
+
input: number;
|
|
9
|
+
output: number;
|
|
10
|
+
cacheRead: number;
|
|
11
|
+
cacheWrite: number;
|
|
12
|
+
/** In dollars, as the model's prices make it. */
|
|
13
|
+
cost: number;
|
|
14
|
+
/** Answers of the model. */
|
|
15
|
+
turns: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Something an agent did lately, as one watching it sees it: a tool it called (its name, whether it worked, how
|
|
19
|
+
* long it took) or a call of the model that failed. Never its arguments or what it returned; of an error, its first
|
|
20
|
+
* line, cut short.
|
|
21
|
+
*/
|
|
22
|
+
export interface TaAgentActivity {
|
|
23
|
+
at: number;
|
|
24
|
+
kind: 'tool' | 'model';
|
|
25
|
+
/** The tool's name, or the model's. */
|
|
26
|
+
name: string;
|
|
27
|
+
ok: boolean;
|
|
28
|
+
/** A tool call without its result yet. */
|
|
29
|
+
running?: boolean;
|
|
30
|
+
error?: string;
|
|
31
|
+
ms?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the agents of this Ta took and did, read from the files of its sessions: for a gateway's console, and
|
|
35
|
+
* any page that shows spending. Nothing said in them leaves.
|
|
36
|
+
*/
|
|
37
|
+
export interface TaUsageServer {
|
|
38
|
+
/** The hours since `since` (a time), by model; an hour with nothing is left out. */
|
|
39
|
+
getUsage(since: number): Promise<TaUsageBucket[]>;
|
|
40
|
+
/** The latest of what the agent of an open session did, newest first, `limit` at most (50 by default, 200 at most). */
|
|
41
|
+
getActivity(sessionId: string, limit?: number): Promise<TaAgentActivity[]>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=usage-protocol.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TA_USAGE_SERVICE = exports.TaUsageServer = void 0;
|
|
4
|
+
exports.TaUsageServer = Symbol('TaUsageServer');
|
|
5
|
+
exports.TA_USAGE_SERVICE = 'TaUsageServer';
|
|
6
|
+
//# sourceMappingURL=usage-protocol.js.map
|